8086汇编输出指定阶数的乘法口诀表(带提示信息,范围:1~181,其中1~9阶表左对齐输出)
Posted u25th_engineer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8086汇编输出指定阶数的乘法口诀表(带提示信息,范围:1~181,其中1~9阶表左对齐输出)相关的知识,希望对你有一定的参考价值。
图 1 程序运行示意(9阶乘法口诀表)
图 2 程序运行示意(8阶乘法口诀表)
图 3 程序运行示意(7阶乘法口诀表)
图 4 程序运行示意(5阶乘法口诀表)
图 5 程序运行示意(1阶乘法口诀表)
图 6 程序运行示意(10阶乘法口诀表)
可以看到,1~9阶的乘法口诀表是左对齐输出的(博主在代码中做了限制),超出10阶就无法对齐再输出。
stack segment stack
db 512 dup(?)
stack ends
data segment
msg db "Enter the rank of the multiplication table you want to be shown:", 0ah, 0dh, '$'
string1 db "Press any key to continue!", 0ah, 0dh, '$'
string2 db "*", '$'
string3 db "=", '$'
string4 db " ", '$'
data ends
code segment
assume ds: data, cs: code, ss: stack
main:
mov ax, stack
mov ss, ax
mov ax, data
mov ds, ax
lea dx, msg
mov ah, 09h
int 21h
call far ptr readsiw
push ax
call far ptr display_table
jmp done
;
; Input: ax register, the rank of the multiplication table to be shown
; Output: None
; Function: To display the multiplication table with specific rank assigned by user
;
display_table proc far
push bp
mov bp,sp
push si
push di
mov si,1
jmp short out_loop
in_loop:
mov di,1
jmp short new_line
display_equation:
mov ax,di
push ax
call far ptr dispsiw
lea dx, string2 ; *
mov ah, 09h
int 21h
pop ax
push ax
mov ax, si
call far ptr dispsiw
pop ax
imul si
push ax
lea dx, string3 ; =
mov ah, 09h
int 21h
pop ax
call far ptr dispsiw
cmp ax, 10
jl two_spaces
push ax
lea dx, string4
mov ah, 09h
int 21h
pop ax
jmp continue_in_loop
two_spaces:
push ax
lea dx, string4
mov ah, 09h
int 21h
lea dx, string4
mov ah, 09h
int 21h
pop ax
jmp continue_in_loop
continue_in_loop:
inc di
new_line:
cmp di,si
jle short display_equation
call far ptr lineFeed
inc si
out_loop:
cmp si,word ptr [bp+6]
jle short in_loop
pop di
pop si
mov sp,bp
pop bp
ret
display_table endp
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
done:
lea dx, string1
mov ah, 09h
int 21h
mov ah, 07h
int 21h
mov ah, 4ch
int 21h
code ends
end main
以上是关于8086汇编输出指定阶数的乘法口诀表(带提示信息,范围:1~181,其中1~9阶表左对齐输出)的主要内容,如果未能解决你的问题,请参考以下文章
8086汇编输出指定阶数的乘法口诀表(带提示信息,范围:1~181,其中1~9阶表左对齐输出)
8086汇编输入一正整数,统计其位数,输出各个位数及反向输出各个位数(逆序数)(输入范围:1~32767,带提示信息)