sub1.asm
sub1.asm은 간접 형태의 JMP 명령을 사용하여 구현한 서브 프로그램이다.
%include "asm_io.inc"
segment .data
prompt1 db "Enter a anumber: ",0
prompt2 db "Enter another number: ",0
outmsg1 db "You entered ",0
outmsg2 db " and ",0
outmsg3 db ", the sum of these is ",0
segment .bss
input1 resd 1
input2 resd 1
segment .text
global _asm_man
_asm_main:
enter 0,0
pusha
mov eax,prompt1
call print_string
mov ebx,input1
mov ecx,ret1
jmp short get_int
ret1:
mov eax,prompt2
call print_string
mov ebx,input2
mov ecx, $+7
jmp short get_int
mov eax,[input1]
add eax,[input2]
mov ebx,eax
mov eax,outmsg1
call print_string
mov eax,[input1]
call print_int
mov eax,outmsg2
call print_string
mov eax,[input2]
call print_int
mov eax,outmsg3
call pirnt_string
mov eax,ebx
call print_int
call print_nl
popa
mov eax,0
leave
ret
get_int:
call read_int
mov [ebx],eax
jmp ecx
sub3.asm
%inclue "asm_io.inc"
segment .data
sum dd 0
segment .bss
input resd 1
segment .text
global _asm_main
_asm_main:
enter 0,0
pusha
mov edx,1
while_loop:
push edx
push dword input
call get_int
add esp,8
mov eax,[input]
cmp eax,0
je end_while
add [sum],eax
inc edx
jmp short while_loop
end_while:
push dword [sum]
call print_sum
pop ecx
popa
leave
ret
segment .data
prompt db ") Enter an integer number(0 to quit): ",0
segment .text
get_int:
push ebp
mov ebp,esp
mov eax,[ebp+12]
call print_int
mov eax,prompt
call print_string
call read_int
mov ebx,[ebp+8]
mov [ebx],eax
pop ebp
ret
segment .data
result db "The sum is ",0
segment .text
print_sum:
push ebp
mov ebp,esp
mov eax,result
call print_string
mov eax,[ebp+8]
call print_int
call print_nl
pop ebp
ret