汇编语言的宏指令及子程序设计从键盘输入10个无符号十进制数,将其转换为二进制数并存放在NUM字节型变量中,找出其中的最大数,并在屏幕上显示出来
时间: 2023-12-21 17:04:25 浏览: 87
以下是汇编语言的宏指令及子程序设计,实现从键盘输入10个无符号十进制数,将其转换为二进制数并存放在NUM字节型变量中,找出其中的最大数,并在屏幕上显示出来:
```
.model small
.stack 100h
.data
NUM db 10 dup(0)
MAX db ?
MSG1 db 10, 13, 'Enter a number: $'
MSG2 db 10, 13, 'The maximum number is: $'
.code
main proc
mov ax, @data
mov ds, ax
; Input 10 decimal numbers and convert to binary
mov cx, 10
mov si, offset NUM
input_loop:
mov ah, 09h
lea dx, MSG1
int 21h
; Read decimal number from keyboard
mov ah, 01h
int 21h
; Check if input is valid decimal digit
cmp al, '0'
jb input_loop
cmp al, '9'
ja input_loop
; Convert decimal digit to binary and store in NUM
sub al, '0'
mov bl, al
mov bh, 0
mov cl, 8
convert_loop:
shr bl, 1
rcl bh, 1
adc bh, 0
dec cl
jnz convert_loop
mov [si], bh
inc si
loop input_loop
; Find maximum number in NUM
mov si, offset NUM
mov al, [si]
mov bl, [si+1]
mov bh, 0
max_loop:
cmp bx, ax
jbe next_num
mov al, bl
mov ah, bh
next_num:
add si, 1
mov bl, [si]
mov bh, 0
loop max_loop
; Display maximum number on screen
mov MAX, al
mov ah, 09h
lea dx, MSG2
int 21h
mov dl, MAX
add dl, '0'
mov ah, 02h
int 21h
; Exit program
mov ah, 4ch
int 21h
main endp
end main
```
阅读全文