汇编语言编程设计输出九九乘法表,从键盘输入选项,查找对应结果并标记输出,数据的
时间: 2024-01-10 15:03:58 浏览: 86
汇编实现九九乘法表输出.pdf
5星 · 资源好评率100%
存储可以用数组实现。下面是汇编语言实现九九乘法表并查找结果的代码:
```
.model small
.stack 100h
.data
row db 9
col db 9
mulTable db 100 dup(0)
prompt db "Enter a number between 1 and 81: $"
result db "The result is: $"
error db "Invalid input. Please try again. $"
.code
main proc
mov ax, @data
mov ds, ax
call displayMenu
call getInput
call checkInput
call calculateResult
call displayResult
mov ah, 4ch
int 21h
main endp
; Display the menu
displayMenu proc
mov ah, 9
mov dx, offset prompt
int 21h
ret
displayMenu endp
; Get input from the user
getInput proc
mov ah, 1
int 21h
sub al, 30h ; Convert from ASCII to binary
mov bl, al
mov ah, 0
int 16h ; Wait for Enter key
ret
getInput endp
; Check if the input is valid
checkInput proc
cmp bl, 0
jbe displayError
cmp bl, 81
ja displayError
ret
displayError:
mov ah, 9
mov dx, offset error
int 21h
jmp main
checkInput endp
; Calculate the result and mark it in the multiplication table
calculateResult proc
mov bh, 1 ; Set the row counter
rowLoop:
mov bl, bh ; Set the column counter
colLoop:
mov al, bh ; Multiply the row and column
mul bl
mov ah, 0 ; Store the result in the multiplication table
mov [mulTable + (bh - 1) * 10 + (bl - 1)], al
inc bl ; Increment the column counter
cmp bl, col
jle colLoop ; If the column counter is less than or equal to 9, go to the next column
inc bh ; Increment the row counter
cmp bh, row
jle rowLoop ; If the row counter is less than or equal to 9, go to the next row
ret
calculateResult endp
; Display the result and mark it in the multiplication table
displayResult proc
mov ah, 9
mov dx, offset result
int 21h
mov al, [mulTable + (bh - 1) * 10 + (bl - 1)] ; Get the result from the multiplication table
add al, 30h ; Convert from binary to ASCII
mov dl, al
mov ah, 2 ; Display the result
int 21h
mov ah, 9 ; Mark the result in the multiplication table
mov dl, 'X'
mov bh, 0 ; Set the attribute to white on black
int 10h
ret
displayResult endp
end main
```
此程序会提示用户输入一个介于1到81之间的数字,然后查找对应的乘法表中的结果并在屏幕上标记输出。如果输入无效,则会显示错误消息并要求用户重新输入。
阅读全文