修改程序,使其从用户输入32位整数列表,然后以相反的顺序显示整数

时间:2014-12-12 22:53:59

标签: assembly masm irvine32

对于我的任务,我需要采取如下所示的程序。

INCLUDE Irvine32.inc

.data
aName BYTE "Abraham Lincoln",0
nameSize = ($ - aName) - 1

.code
main PROC

; Push the name on the stack.
    mov ecx,nameSize
    mov esi,0

L1: movzx eax,aName[esi]    ; get character
    push eax    ; push on stack
    inc esi
    Loop L1

; Pop the name from the stack, in reverse,
; and store in the aName array.
    mov ecx,nameSize
    mov esi,0

L2: pop eax ; get character
    mov aName[esi],al   ; store in string
    inc esi
    Loop L2

; Display the name.
    mov edx,OFFSET aName
    call Writestring
    call Crlf

    exit
main ENDP
END main

并修改程序,以便从用户输入32位整数列表,然后以相反的顺序显示整数。构建失败,说明

上的指令操作数必须相同
mov aName[esi],al ; store in string 

这是完整的计划。我没有做什么?

INCLUDE Irvine32.inc
.data
   aName WORD 5 DUP (?)
   nameSize = 5
.code

main PROC

   mov  edx, OFFSET aName
   mov  ecx, 4          ;buffer size - 1


   ; Push the name on the stack.
   mov ecx,nameSize
   mov esi,0
   L1: 
     Call ReadInt
     push eax ; push on stack
     inc esi
   Loop L1
   ; Pop the name from the stack, in reverse,
   ; and store in the aName array.
   mov ecx,nameSize
   mov esi,0
   L2: pop eax ; get character
     mov aName[esi],al ; store in string
     inc esi
   Loop L2
   ; Display the name.
   mov edx,OFFSET aName
   call Writestring
   call Crlf
   exit
   main ENDP
END main

1 个答案:

答案 0 :(得分:1)

  1. 此声明设置为16位值,您的赋值大约为32位整数!

    aName WORD 5 DUP (?)
    
  2. 在汇编程序中,大多数时候操作数必须与大小有关。 AL显然是一个字节,而你将aName定义为word类型!两者都需要成为dword。

    mov aName[esi],al ; store in string
    
  3. 示例程序使用Writestring显示以零结尾的文本。为什么你还希望它还显示一个非零终止的缓冲区,用数字代替字符?

    mov edx,OFFSET aName
    call Writestring
    
  4. 您能否看到此代码不需要同时使用ESI?

    ; Push the name on the stack.
    mov ecx,nameSize
    mov esi,0
    L1: 
     Call ReadInt
     push eax ; push on stack
     inc esi
    Loop L1