2017-09-08 26 views
1

私は練習問題を解決しようとしています。タスクは、端末から10個の整数を読み込み、逆順に出力することです。これを行うには、スタックを使用する必要があります。私はプログラムを実行し、1から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 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 

:ジャストラインadd esp, 4を削除

    Should Be: 
10     10 
8     9 
6     8 
4     7 
2     6 
-1217249280   5 
-1079315368   4 
0     3 
-1079315312   2 
-1079315336   1 

答えて

3

を私はこれを試してみました。
スタックポインタはすでにpop eaxだけインクリメントされています。