我不允许使用循环来打印总和,我只能使用跳转
.model small
.stack 100h
.data
input_buffer1 db 10 DUP ('$') ; Define a buffer to store the first input string
input_buffer2 db 10 DUP ('$') ; Define a buffer to store the second input string
message1 db 'Enter the first integer: $' ; Prompt message for the first input
message2 db 'Enter the second integer: $' ; Prompt message for the second input
newline db 13, 10, '$' ; Newline character to print a newline
result_message db 'The sum is: $' ; Message for printing the sum
.code
main:
mov ax, @data ; Load the address of the data segment into AX
mov ds, ax ; Set DS to point to the data segment
; Prompt for the first input
mov ah, 09h
mov dx, offset message1
int 21h
; Read the first input
mov ah, 0Ah ; Function to read a string
mov dx, offset input_buffer1
int 21h ; Call interrupt 21h
; Print a newline character
mov ah, 09h
mov dx, offset newline
int 21h
; Prompt for the second input
mov ah, 09h
mov dx, offset message2
int 21h
; Read the second input
mov ah, 0Ah ; Function to read a string
mov dx, offset input_buffer2
int 21h ; Call interrupt 21h
; Convert the first input to integer
mov si, offset input_buffer1 + 2 ; Skip the first two bytes (length and '$')
mov al, [si] ; Load the first character
sub al, '0' ; Convert ASCII character to integer
mov bl, al ; Save the integer in BL
; Convert the second input to integer
mov si, offset input_buffer2 + 2 ; Skip the first two bytes (length and '$')
mov al, [si] ; Load the first character
sub al, '0' ; Convert ASCII character to integer
add bl, al ; Add the second input (AL) to the first input (BL)
; Print a newline character
mov ah, 09h
mov dx, offset newline
int 21h
; Print the sum
mov ah, 09h
mov dx, offset result_message
int 21h
; Convert the sum to ASCII and print
mov dl, bl ; Move the result to DL for printing
add dl, '0' ; Convert integer to ASCII character
mov ah, 02h ; Function to print a character
int 21h ; Call interrupt 21h
end main
组织100小时 。数据 result db 10,13,"加法结果:$" 值数据库“00000 $” 换行符 db 10, 13, '$'
.代码 主程序 移动斧头,@data mov ds, 斧头 移动斧头, 0 ;寻找加法 移动斧头, 6 添加斧头,3
;converting result to ASCII
mov cx, 10
mov di, offset value
mov bx, 4
convert_to_ascii:
xor dx, dx
div cx
add dl, '0'
mov [di+bx], dl
dec bx
cmp ax, 0
jnz convert_to_ascii
; printing result
mov dx, offset result
mov ah, 09h
int 21h
mov dx, offset value
int 21h
mov ah, 00h
int 21h
main endp
结束电源