Assembly 汇编堆栈-反向输入和打印输出
我正在努力解决一个练习题。任务是从终端读取10个整数,并按相反顺序打印出来。为此,应使用堆栈。我试过这个:Assembly 汇编堆栈-反向输入和打印输出,assembly,stack,user-input,nasm,reverse,Assembly,Stack,User Input,Nasm,Reverse,我正在努力解决一个练习题。任务是从终端读取10个整数,并按相反顺序打印出来。为此,应使用堆栈。我试过这个: %include "asm_io.inc" segment .data prompt db "Please enter a number: ", 0 segment .text global asm_main asm_main: enter 0,0 pusha mov ecx, 10 ; for
%include "asm_io.inc"
segment .data
prompt db "Please enter a number: ", 0
segment .text
global asm_main
asm_main:
enter 0,0
pusha
mov ecx, 10 ; for loop counter
for_loop:
mov eax, prompt
call print_string ; print prompt
call read_int ; read input
push dword eax ; push input to stack
loop for_loop
mov ecx, 10 ; set loop counter for output
swap_loop:
pop eax ; get last input from stack
call print_int
call print_nl
add esp, 4 ; increment esp for next value to take from stack
loop swap_loop
popa
mov eax, 0
leave
ret
当我执行程序并依次输入从1到10的所有数字时,我得到以下结果:
Should Be:
10 10
8 9
6 8
4 7
2 6
-1217249280 5
-1079315368 4
0 3
-1079315312 2
-1079315336 1
只需删除行
添加esp,4
堆栈指针已经增加了
pop eax