Skip to content

Commit e89d2ab

Browse files
committed
added chapter 01 lessons
1 parent f5113be commit e89d2ab

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; ====================================================
2+
; AVR-Programming-with-Assembly Copyright(C) 2017 Furkan Türkal
3+
; This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4+
; and you are welcome to redistribute it under certain conditions; See
5+
; file LICENSE, which is part of this source code package, for details.
6+
; ====================================================
7+
8+
; Example : Purpose of the Assembly example
9+
10+
; Ports : Required ports

Chapter 01 - Basics/02-org-0-main.asm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; ====================================================
2+
; DLL-Injection-with-Assembly Copyright(C) 2017 Furkan Türkal
3+
; This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4+
; and you are welcome to redistribute it under certain conditions; See
5+
; file LICENSE, which is part of this source code package, for details.
6+
; ====================================================
7+
8+
; Example : Purpose of the ".org 0" (Indispensable)
9+
10+
; The command at the 0th place (also known as ".org 0"), is the first executed command when the first time it is started or reset
11+
12+
.org 0 ; The 0th address in the program memory, allows the next command to be written.
13+
rjmp main ; Redirecting to main (or whatever you want) which we want to work first.
14+
15+
main
16+
;Codes
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; ====================================================
2+
; DLL-Injection-with-Assembly Copyright(C) 2017 Furkan Türkal
3+
; This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4+
; and you are welcome to redistribute it under certain conditions; See
5+
; file LICENSE, which is part of this source code package, for details.
6+
; ====================================================
7+
8+
; Example : Activate the LED if button pressed
9+
10+
; Ports : LED -> PORTB's 5th pin
11+
12+
.org 0
13+
rjmp main
14+
15+
main:
16+
ldi r16, 0x20 ; 0x20=0010 0000 -> PORTB nin 5. pinini output yapmak istiyoruz, o nedenle 5. bit 1
17+
out DDRB, r16 ; PortB nin data direction registeri DDRB ye r16 daki degeri yaziyoruz
18+
19+
loop_main:
20+
sbi PORTB, 5 ; PORTB nin 5. pinini lojik 1 yapiyoruz yani set ediyoruz ve led yaniyor.
21+
rjmp loop_main ; Programin loop_main etiketine giderek sonsuz dongude calismasini sagliyoruz

Chapter 01 - Basics/04-led-button.asm

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; ====================================================
2+
; DLL-Injection-with-Assembly Copyright(C) 2017 Furkan Türkal
3+
; This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4+
; and you are welcome to redistribute it under certain conditions; See
5+
; file LICENSE, which is part of this source code package, for details.
6+
; ====================================================
7+
8+
; Example : Activate the LED if button pressed
9+
10+
; Ports : LED -> PORTB's 5th pin
11+
; : Button -> PORTB's 6th pin
12+
13+
.org 0
14+
rjmp main
15+
16+
main:
17+
ldi r16, 0x20 ; Set PORTB's 5th pin to output mode [0x20 = 0010 0000, r16 = PORTB]
18+
out DDRB, r16 ; Write the r16's value at the PORTB's DDRB (DataDirectionRegister)
19+
sbi PORTB, 6 ; Activate the PB6's pull-up resistor. When you press the button, you will read 0, else you will read 1
20+
21+
loop_main:
22+
sbis PINB, 6 ; If PB6 pin's value == 1 (button_not_pressed), skip next command
23+
rjmp button_led ; If PB6 pin's value == 0 (button_pressed), dont skip and execute command
24+
cbi PORTB, 5 ; Deactivate the LED If button is not pressed
25+
rjmp loop_main ; Go to loop_button tag via RelativeJump and make it work in an infinite loop
26+
27+
button_led:
28+
sbi PORTB, 5 ; If button is pressed, activate the LED
29+
rjmp loop_main ; Infinite loop

Chapter 01 - Basics/05-led-blink.asm

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; ====================================================
2+
; DLL-Injection-with-Assembly Copyright(C) 2017 Furkan Türkal
3+
; This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4+
; and you are welcome to redistribute it under certain conditions; See
5+
; file LICENSE, which is part of this source code package, for details.
6+
; ====================================================
7+
8+
; Example : Blink the LED at intervals of about 700 ms.
9+
10+
; Ports : LED -> PORTB's 5th pin
11+
12+
.org 0
13+
rjmp main
14+
15+
main:
16+
ldi r16, 0x20 ; Set PORTB's 5th pin to output mode [0x20 = 0010 0000, r16 = PORTB]
17+
out DDRB, r16 ; Write the r16's value at the PORTB's DDRB (DataDirectionRegister)
18+
clr r17 ; Using r17 as a tempory to activate/deactivate the LED
19+
20+
loop_main:
21+
eor r17, r16 ; XOR the r16's unchanged 0x20 data with r17 (this command will change the 5th bit with 1 and 0, on every tick)
22+
out PORTB, r17 ; Write the r17's value at the PORTB
23+
call delay_ms ; Call the delay function
24+
rjmp loop_main ; Go to loop_main tag via RelativeJump and make it work in an infinite loop
25+
26+
delay_ms: ; Delay function (700ms)
27+
push r16 ; We need to use loop_main's r16 and r17's values in delay_ms function
28+
push r17 ; Using the push command, we record the values inside these registers into stack
29+
30+
ldi r16, 0x40 ; Run the loop 0x400000 times
31+
ldi r17, 0x00 ; Run the ~12 million command cycle
32+
ldi r18, 0x00 ; ~0.7s time delay will be obtained for 16Mhz working frequency
33+
34+
_w0:
35+
dec r18 ; Decrement by 1 the r18's value
36+
brne _w0 ; If the result of reduction is not 0, callback _w0 branch
37+
dec r17 ; Decrement by 1 the r17's value
38+
brne _w0 ; If the result of reduction is not 0, callback _w0 branch
39+
dec r16 ; Decrement by 1 the r16's value
40+
brne _w0 ; If the result of reduction is not 0, return _w0 branch
41+
pop r17 ; Pop the latest pushed r17 before returning from function
42+
pop r16 ; Pop the latest pushed r16 before returning from function
43+
ret ; Return from the function

0 commit comments

Comments
 (0)