assembly lecture 9 introduction to 8086 introduction to subprograms · 2019. 11. 13. · how to...
TRANSCRIPT
![Page 1: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/1.jpg)
Introduction to 8086 Assembly Lecture 9
Introduction to Subprograms
![Page 2: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/2.jpg)
Indirect addressingsegment .datal1: dd 111segment .text ⠇ mov eax, l1 call print_int call print_nl
mov eax, [l1] call print_int call print_nl mov ecx, l1 mov eax, [ecx] call print_int call print_nl
indirect.asm
![Page 3: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/3.jpg)
Indirect addressingsegment .datal1: dd 111segment .text ⠇ mov eax, l1 call print_int call print_nl
mov eax, [l1] call print_int call print_nl mov ecx, l1 mov eax, [ecx] call print_int call print_nl
indirect.asm
![Page 4: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/4.jpg)
Indirect addressingsegment .datal1: dd 111segment .text ⠇ mov eax, l1 call print_int call print_nl
mov eax, [l1] call print_int call print_nl mov ecx, l1 mov eax, [ecx] call print_int call print_nl
indirect.asm
![Page 5: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/5.jpg)
Indirect addressingsegment .datal1: dd 111 dd 222 dd 444
segment .text ⠇ mov ecx, l1
mov eax, [ecx] call print_int call print_nl
indirect2.asm
mov eax, [ecx+1] call print_int call print_nl
mov eax, [ecx+4] call print_int call print_nl
mov eax, [ecx+8] call print_int call print_nl
indirect2.asm (cont.)
![Page 6: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/6.jpg)
Indirect addressingsegment .datal1: dd 111 dd 222 dd 444
segment .text ⠇ mov ecx, l1
mov eax, [ecx] call print_int call print_nl
indirect2.asm
mov eax, [ecx+1] call print_int call print_nl
mov eax, [ecx+4] call print_int call print_nl
mov eax, [ecx+8] call print_int call print_nl
indirect2.asm (cont.)
How does the assembler do this?
![Page 7: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/7.jpg)
Indirect addressing
mov eax, [ecx] mov ax, [ecx] mov al, [ecx]
![Page 8: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/8.jpg)
How to implement subprograms?
● Subprogram● function● subroutine● procedure● routine● method● callable
void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
![Page 9: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/9.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0
segment .text ⠇
⠇
print_salam: mov eax, msg call print_string
![Page 10: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/10.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0
segment .text ⠇ jmp print_salam ⠇
print_salam: mov eax, msg call print_string
![Page 11: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/11.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0
segment .text ⠇ jmp print_salaml1: ⠇
print_salam: mov eax, msg call print_string
![Page 12: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/12.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0
segment .text ⠇ jmp print_salaml1: ⠇
print_salam: mov eax, msg call print_string
return address
![Page 13: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/13.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0
segment .text ⠇ jmp print_salaml1: ⠇
print_salam: mov eax, msg call print_string jmp l1
simplefunc1.asm
return address
![Page 14: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/14.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0
segment .text ⠇ jmp print_salaml1: ⠇
print_salam: mov eax, msg call print_string jmp l1
simplefunc1.asm
What's wrong?
return address
![Page 15: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/15.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0
segment .text ⠇ jmp print_salaml1: ⠇ jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string jmp ?
simplefunc2.asm
return address
![Page 16: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/16.jpg)
Indirect jump
Direct Jump: jmp l1
Indirect Jump: mov eax, l1 jmp eax
![Page 17: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/17.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ mov edx, l1 jmp print_salaml1: mov edx, l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string jmp edx
simplefunc3.asm
return address
![Page 18: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/18.jpg)
How to implement subprograms?void print_salam(void);
int main() {
print_salam(); }
void print_salam() { printf("Salaaaaam!\n");}
segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ mov edx, l1 jmp print_salaml1: mov edx, l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string jmp edx
simplefunc3.asm
Limitations?
return address
![Page 19: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/19.jpg)
The stack
http://carbon.materialwitness.co/book-stack/
http://freepngimg.com/png/25783-coin-stack-transparent-image
https://pixabay.com/en/plate-stack-tableware-plate-stack-629970/
![Page 20: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/20.jpg)
The stackMemory Memory
![Page 21: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/21.jpg)
Implementing the stackStack Segment Stack Segment
![Page 22: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/22.jpg)
Implementing the stackStack Segment Stack Segment
x86
![Page 23: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/23.jpg)
Implementing the stackStack Segment Stack Segment
x86(why?)
![Page 24: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/24.jpg)
Implementing the stackstack segment
2096
2092
2088
2100
![Page 25: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/25.jpg)
Stack Pointer (SP, ESP, RSP)stack segment
2096
2092
2088
2100
2088
ESP
CPU
![Page 26: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/26.jpg)
Pushing on the stackstack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
![Page 27: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/27.jpg)
Push EAX on the stackstack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
![Page 28: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/28.jpg)
Push EAX on the stackstack segment
2096
2092
2088
2100
2084ESP
CPU
44200EAX
![Page 29: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/29.jpg)
Push EAX on the stackstack segment
2096
2092
2088
2100
2084ESP
CPU
44200EAX
sub esp, 4
![Page 30: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/30.jpg)
Push EAX on the stackstack segment
2096
2092
2088
2100
2084ESP
CPU
44200EAX
44200
sub esp, 4
![Page 31: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/31.jpg)
Push EAX on the stackstack segment
2096
2092
2088
2100
2084ESP
CPU
44200EAX
44200
sub esp, 4mov [esp], eax
![Page 32: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/32.jpg)
Push EAX on the stackstack segment
2096
2092
2088
2100
2084ESP
CPU
44200EAX
44200
sub esp, 4mov [esp], eax
|||push eax
![Page 33: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/33.jpg)
Pop into EBXstack segment
2096
2092
2088
2100
2084ESP
CPU
44200EAX
44200
EBX
![Page 34: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/34.jpg)
Pop into EBXstack segment
2096
2092
2088
2100
2084ESP
CPU
44200EAX
44200
44200EBX
mov ebx, [esp]
![Page 35: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/35.jpg)
Pop into EBXstack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
44200
44200EBX
mov ebx, [esp]add esp, 4
![Page 36: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/36.jpg)
Pop into EBXstack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
44200
44200EBX
mov ebx, [esp]add esp, 4
|||pop ebx
![Page 37: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/37.jpg)
just pop 4 bytes (store nowhere)stack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
EBX
pop ebx
![Page 38: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/38.jpg)
just pop 4 bytes (store nowhere)stack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
EBX
pop ebx
OR?add esp, 4
![Page 39: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/39.jpg)
just pop 4 bytes (store nowhere)stack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
EBX
pop ebx
OR?add esp, 4
add esp, 20
![Page 40: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/40.jpg)
reserve memory on stackstack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
EBX
push edx
![Page 41: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/41.jpg)
reserve memory on stackstack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
EBX
push edx
OR?sub esp, 4
![Page 42: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/42.jpg)
reserve memory on stackstack segment
2096
2092
2088
2100
2088ESP
CPU
44200EAX
EBX
push edx
OR?sub esp, 4
sub esp, 24
![Page 43: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/43.jpg)
Push and Pop
Push reg/mem/immed
Pop reg/mem
![Page 44: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/44.jpg)
Practice
push eax push ebx
pop eax pop ebx
![Page 45: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/45.jpg)
pusha and popa
● 8086: ○ pusha: Push AX, CX, DX, BX, SP, BP, SI, DI○ popa: Pop DI, SI, BP, BX, DX, CX, AX.
● 80386: (netwide assembler, what we use)○ pusha, pushad: Push EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI○ popa, popad: Pop EDI, ESI, EBP, EBX, EDX, ECX, EAX.
● 80386: some other assemblers○ pusha: Push AX, CX, DX, BX, SP, BP, SI, DI○ pushad: Push EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI○ popa: Pop DI, SI, BP, BX, DX, CX, AX.○ popad: Pop EDI, ESI, EBP, EBX, EDX, ECX, EAX
● 64 bit○ no pusha/popa in 64-bit mode
![Page 46: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/46.jpg)
pushf and popf
● push and pop FLAGS/EFLAGS register● some assemblers use (pushf/pushfd/pushfq, etc.)
![Page 47: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/47.jpg)
Back to subroutinessegment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ mov edx, l1 jmp print_salaml1: mov edx, l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string jmp edx
simplefunc3.asm
![Page 48: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/48.jpg)
Back to subroutinessegment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ mov edx, l1 jmp print_salaml1: mov edx, l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string jmp edx
simplefunc3.asm segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ push l1 jmp print_salaml1: push l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string ??
simplefunc4.asm
![Page 49: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/49.jpg)
Back to subroutinessegment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ mov edx, l1 jmp print_salaml1: mov edx, l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string jmp edx
simplefunc3.asm segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ push l1 jmp print_salaml1: push l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string pop edx jmp edx
simplefunc4.asm
![Page 50: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/50.jpg)
the CALL instructionsegment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ mov edx, l1 jmp print_salaml1: mov edx, l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string jmp edx
simplefunc3.asm segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ push l1 jmp print_salaml1: push l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string pop edx jmp edx
simplefunc4.asm segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salaml1:
call print_salaml2: ⠇print_salam: mov eax, msg call print_string pop edx jmp edx
simplefunc5.asm
![Page 51: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/51.jpg)
the CALL instructionsegment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ mov edx, l1 jmp print_salaml1: mov edx, l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string jmp edx
simplefunc3.asm segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇ push l1 jmp print_salaml1: push l2 jmp print_salaml2: ⠇print_salam: mov eax, msg call print_string pop edx jmp edx
simplefunc4.asm segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam
call print_salam ⠇print_salam: mov eax, msg call print_string pop edx jmp edx
simplefunc5.asm
![Page 52: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/52.jpg)
the CALL instruction
CALL is merely a form of jump!
![Page 53: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/53.jpg)
the CALL instruction
CALL is merely a form of jump!
call label1
● Push return address on stack● jump to label1
![Page 54: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/54.jpg)
2092
2088
call print_salam
popa
:
mov eax, msg print_salam = 1024
1008
1008EIP
CPU
2088ESP
segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam popa ⠇
print_salam: mov eax, msg call print_string pop edx jmp edx
call print_salam
![Page 55: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/55.jpg)
2092
2088
1008
call print_salam
popa
:
mov eax, msg print_salam = 1024
1008
1008EIP
CPU
2084ESP
segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam popa ⠇
print_salam: mov eax, msg call print_string pop edx jmp edx
call print_salam
![Page 56: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/56.jpg)
2092
2088
1008
call print_salam
popa
:
mov eax, msg print_salam = 1024
1008
1024EIP
CPU
2084ESP
segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam popa ⠇
print_salam: mov eax, msg call print_string pop edx jmp edx
call print_salam
![Page 57: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/57.jpg)
returning from a subroutinesegment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam
call print_salam ⠇print_salam: mov eax, msg call print_string pop edx jmp edx
simplefunc5.asm
![Page 58: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/58.jpg)
the RET instructionsegment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam
call print_salam ⠇print_salam: mov eax, msg call print_string pop edx jmp edx
simplefunc5.asm segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam
call print_salam ⠇print_salam: mov eax, msg call print_string ret
simplefunc6.asm
![Page 59: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/59.jpg)
the RET instructionsegment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam
call print_salam ⠇print_salam: mov eax, msg call print_string pop edx jmp edx
simplefunc5.asm segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam
call print_salam ⠇print_salam: mov eax, msg call print_string ret
simplefunc6.asm
![Page 60: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/60.jpg)
the RET instruction
RET is merely a form of jump!
![Page 61: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/61.jpg)
the RET instruction
RET is merely a form of jump!
ret
● jump to the address stored on top of stack● pop stack
![Page 62: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/62.jpg)
2092
2088
1008
call print_salam
popa
:
ret print_salam = 1024
1008
1032EIP
CPU
2084ESP
segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam popa ⠇
print_salam: mov eax, msg call print_string ret
ret
![Page 63: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/63.jpg)
2092
2088
1008
call print_salam
popa
: print_salam = 1024
1008
1008EIP
CPU
2088ESP
segment .datamsg: db "Salaaaaam!", 10, 0segment .text ⠇
call print_salam popa ⠇
print_salam: mov eax, msg call print_string ret
ret
ret
![Page 64: Assembly Lecture 9 Introduction to 8086 Introduction to Subprograms · 2019. 11. 13. · How to implement subprograms? Subprogram function subroutine procedure routine method](https://reader033.vdocuments.us/reader033/viewer/2022051903/5ff3f5d0c7d911086d1ad939/html5/thumbnails/64.jpg)
What else?
● parameters (arguments)● local variables● return values