8086汇编求最小公约数(输入范围:-32768~32767,有提示信息)
Posted u25th_engineer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8086汇编求最小公约数(输入范围:-32768~32767,有提示信息)相关的知识,希望对你有一定的参考价值。
图 1 运行示意(正数、负数)
图 2 运行示意(四位整数)
图 3 运行示意(五位整数)
图 4 运行示意(正数、负数)
stack segment stack
db 512 dup(?)
stack ends
data segment
string1 db 'Enter the first number M:', 0ah, 0dh, '$'
string2 db 'Enter the second number N:', 0ah, 0dh, '$'
string3 db 'The greatest common divisor(GCD) of M and N is:', 0ah, 0dh, '$'
data ends
code segment
assume ds: data, cs: code, ss: stack
start:
mov ax, stack
mov ss, ax
mov ax, data
mov ds, ax
lea dx, string1
mov bh, ah
mov ah, 09h
int 21h
mov ah, bh
push ax
call far ptr readsiw
lea dx, string2
mov bh, ah
mov ah, 09h
int 21h
mov ah, bh
push ax
call far ptr readsiw
push ax
call far ptr gcd
lea dx, string3
mov bh, ah
mov ah, 09h
int 21h
mov ah, bh
call far ptr dispsiw
call far ptr lineFeed
jmp done
readsiw proc far
push bx
push cx
push dx
xor bx, bx
xor cx, cx
mov ah, 1
int 21h
cmp al, '+'
jz rsiw1
cmp al, '-'
jnz rsiw2
mov cx, -1
rsiw1:
mov ah, 1
int 21h
rsiw2:
cmp al, '0'
jb rsiw3
cmp al, '9'
ja rsiw3
sub al, 30h
xor ah, ah
shl bx, 1
mov dx, bx
shl bx, 1
shl bx, 1
add bx, dx
add bx, ax
jmp rsiw1
rsiw3:
cmp cx, 0
jz rsiw4
neg bx
rsiw4:
mov ax, bx
pop dx
pop cx
pop bx
ret
readsiw endp
dispsiw proc far
push ax
push bx
push dx
test ax, ax
jnz dsiw1
mov dl, '0'
mov ah, 2
int 21h
jmp dsiw5
dsiw1:
jns dsiw2
mov bx, ax
mov dl, '-'
mov ah, 2
int 21h
mov ax, bx
neg ax
dsiw2:
mov bx, 10
push bx
dsiw3:
cmp ax, 0
jz dsiw4
xor dx, dx
div bx
add dl, 30h
push dx
jmp dsiw3
dsiw4:
pop dx
cmp dl, 10
je dsiw5
mov ah, 2
int 21h
jmp dsiw4
dsiw5:
pop dx
pop bx
pop ax
ret
dispsiw endp
lineFeed proc far
push ax
push dx
mov dl, 0dh
mov ah, 2
int 21h
mov dl, 0ah
mov ah, 2
int 21h
pop dx
pop ax
ret
lineFeed endp
gcd proc far
push bp
mov bp,sp
push si
push di
mov si,word ptr [bp+6]
mov di,word ptr [bp+8]
jmp short gcd_judge
gcd_judge:
mov ax,si
cwd
idiv di
mov si,dx
mov ax,dx
xor di,ax
mov ax,di
xor si,ax
mov ax,si
xor di,ax
jne short gcd_judge
mov ax,si
jmp short gcd_done
gcd_done:
pop di
pop si
pop bp
ret
gcd endp
done:
mov ax, 4c00h
int 21h
code ends
end start
以上是关于8086汇编求最小公约数(输入范围:-32768~32767,有提示信息)的主要内容,如果未能解决你的问题,请参考以下文章
8086汇编求整形数组的最大值与最小值(函数实现,输入范围:-32768~32767)
8086汇编求整形数组的最大值与最小值(函数实现,输入范围:-32768~32767)
8086汇编求整形数组的最大值与最小值(函数实现,输入范围:-32768~32767)
8086汇编求整形数组的最大值与最小值(函数实现,输入范围:-32768~32767)