[英]How do i input a more than 1 digit number?
我想检查它们是否相等、不相等、更大或更小
Dosseg
.model small
.stack 100h
.data
MsgEq db 'Numbers are Equal $'
MsgUneq db 'Numbers are Unequal and $'
MsgGr db ' First Number is greater than second number $'
MsgLs db ' First Number is lesser than second number $'
.code
main proc
mov ax, @data
mov ds, ax
mov ah, 1 ; input first number
int 21h
mov bl, al ; saving first number to bl from al
mov al, 1 ; input second number
int 21h
mov cl, al ; saving second number to cl from al
L1:
cmp bl,cl ; Comparing whether they are equal or not
je EQUAL ; Jump to Equal box, where we print the equal msg
mov dl, 10 ; for next line feed
mov ah, 2
int 21h
mov dl, 13 ; for carriage return
mov ah, 2
int 21h
mov dx, offset MsgUneq ; but if not equal, then print msg they are not equal
mov ah, 9
int 21h
cmp bl, cl ; again compare to check the first is greater or lesser
jge Greater ; if greater, jump to greater to print a greater msg
mov dx, offset MsgLs ; but if not greater, print lesser msg
mov ah, 9
int 21h
jmp PRINT
Greater:
mov dx, offset MsgGr
mov ah, 9
int 21h
jmp PRINT
EQUAL:
mov dl, 10 ; for next line feed
mov ah, 2
int 21h
mov dl, 13 ; for carriage return
mov ah, 2
int 21h
mov dx, offset MsgEq
mov ah, 9
int 21h
jmp PRINT
PRINT:
mov ah,4ch
int 21h
main endp
end main
Dosseg
.model small
.stack 100h
.data
First DB 0 ; Variable for the binary number 0..255.
Second DB 0 ; Variable for the binary number 0..255.
MsgPrompt db 'Enter two numbers between 0 and 255:',13,10,'$'
MsgEq db 'Numbers are Equal.',13,10,'$'
MsgUneq db 'Numbers are Unequal and $'
MsgGr db ' First Number is greater than second number.',13,10,'$'
MsgLs db ' First Number is lesser than second number.',13,10,'$'
.code
main proc
mov ax, @data
mov ds, ax
MOV DX, offset MsgPrompt
MOV AH,9
INT 21h ; Display the prompt.
InputFirst:
mov ah, 1 ; input first number
int 21h
CMP AL,0Dh ; End of input?
JE InputSecond
SUB AL,'0' ; Convert decimal digit to binary number.
mov bl, al ; saving first number to bl from al
MOV DL,10
MOV AL,[First]
MUL DL
ADD AL,BL
MOV [First],AL
JMP InputFirst
InputSecond:
; That was WRONG! mov al, 1 ; input second number
MOV AH, 1 ; input second number
int 21h
CMP AL,0Dh ; End of input?
JE Compare
SUB AL,'0' ; Convert decimal digit to binary number.
mov cl, al ; saving second number to cl from al
MOV DL,10
MOV AL,[Second]
MUL DL
ADD AL,CL
MOV [Second],AL
JMP InputSecond
Compare:
MOV BL,[First]
MOV CL,[Second]
cmp bl,cl ; Comparing whether they are equal or not
je EQUAL ; Jump to Equal box, where we print the equal msg
mov dx, offset MsgUneq ; but if not equal, then print msg they are not equal
mov ah, 9
int 21h
cmp bl, cl ; again compare to check the first is greater or lesser
jge Greater ; if greater, jump to greater to print a greater msg
mov dx, offset MsgLs ; but if not greater, print lesser msg
mov ah, 9
int 21h
jmp PRINT
Greater:
mov dx, offset MsgGr
mov ah, 9
int 21h
jmp PRINT
EQUAL:
mov dx, offset MsgEq
mov ah, 9
int 21h
; jmp PRINT
PRINT: ; Better call this label Exit:
mov ah,4ch
int 21h
main endp
end main
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.