用8086指令系统求输入两个数字的平方差
时间: 2023-06-20 16:06:27 浏览: 73
以下是使用8086汇编语言实现输入两个数字的平方差的代码:
```
.model small
.stack 100h
.data
num1 db ?
num2 db ?
diff dw ?
message1 db 'Enter first number:$'
message2 db 'Enter second number:$'
result db 'The difference of their squares is:$'
.code
main proc
mov ax, @data
mov ds, ax
; input num1
mov ah, 9
lea dx, message1
int 21h
mov ah, 1
int 21h
sub al, 30h
mov num1, al
; input num2
mov ah, 9
lea dx, message2
int 21h
mov ah, 1
int 21h
sub al, 30h
mov num2, al
; calculate diff
mov al, num1
mov bl, num2
mul al
mov cl, al
mov al, bl
mul al
sub cl, ax
mov diff, cx
; output result
mov ah, 9
lea dx, result
int 21h
mov ax, diff
call display_word
mov ah, 4ch
int 21h
main endp
display_word proc
push ax
push bx
push cx
push dx
mov bx, 10
mov cx, 0
loop1:
xor dx, dx
div bx
push dx
inc cx
test ax, ax
jnz loop1
loop2:
pop dx
add dl, 30h
mov ah, 2
int 21h
dec cx
jnz loop2
pop dx
pop cx
pop bx
pop ax
ret
display_word endp
end main
```
上述代码使用了8086汇编语言,通过 BIOS 中断来实现输入和输出。首先输入两个数字,然后计算它们的平方差,最后输出结果。在输出结果时,还需要调用一个 display_word 过程,将双字转换为字符串输出。