解决汇编中两个数字相加的练习

Solve the exercise of adding two numbers in assembly

我需要你的帮助来解决这个机器语言练习。

Write a program in assembly language in which a procedure is defined that has two parameters and calculates the sum of the first parameter and the second parameter and puts it in the second parameter. Use this procedure to write a program that receives two one-digit numbers from the keyboard and displays the sum of the two. Suppose the sum of two numbers becomes one digit.


我的代码:

nextline macro
    mov ah,2
    mov dl,13
    int 21h
    mov dl,10
    int 21h
endm
.MODEL SMALL
 .STACK 64

 .DATA
   msg1  DB  'Enter the character : $'
   msg2  DB  'The next character is : $'
   data1  dw  ?

 .CODE
   MAIN:
     MOV AX, @DATA             
     MOV DS, AX

     LEA DX, msg1           
     MOV AH, 9
     INT 21H

     MOV AH, 1                
     INT 21H
     mov data1,ax 
     
     push data1
     
     CALL NEXT_CHAR
     
     pop data1
                   
     nextline
     LEA DX, msg2          
     MOV AH, 9
     INT 21H

     MOV AH, 2                  
     MOV Dx, data1
     INT 21H

     MOV AH, 4CH                 
     INT 21H




 NEXT_CHAR PROC

    mov bp,sp
    push bx
                
    MOV Bx, [bp+2]
    INC BL
    mov [bp+2],bx 
    
    pop bx
    RET           
 NEXT_CHAR ENDP

END MAIN

您没看懂任务描述。

a procedure is defined that has two parameters and calculates the sum of the first parameter and the second parameter and puts it in the second parameter.

两个显然你现在的程序只用了1个参数
将它放在第二个参数中为此,您需要通过引用传递第二个参数(而不是像第一个参数那样通过值传递)

write a program that receives two one-digit numbers from the keyboard

来自键盘的两个一位数字 这意味着您需要调用 DOS.GetCharacter 函数 01h 的两个实例,而不仅仅是您现在拥有的那个.

and displays the sum of the two. Suppose the sum of two numbers becomes one digit.

假设两个数之和为一位数这将极大地简化您的任务。要从数字 [0,9] 转换为字符 ["0","9"],只需添加 48,然后使用 DOS.PrintChar 函数 02h 显示该字符,您在 DL 中为其提供字符而不是像你那样 DX


我不愿意提供更多代码,因为我相信您可能只是没有很好地理解这个任务。再试一次。您可以随时 post 在接下来的努力中提出另一个问题...