.please help me I want opearte the code program
.model large
.stack 4096
.data
msg db 0dh, 0ah, "Demonisch Basic Assembly Language Calculator", 0dh, 0ah, 0dh, 0ah, "Press return when each number is entered", 0dh, 0ah, "(done automatically if 4 digits is entered)", 0dh, 0ah, "You may put + or - in front of a number (default is +)$"
msgN1 db 0dh, 0ah, "Enter first number: $"
msgO db 0dh, 0ah, "Operation ([+][-][*][/]): $"
msgN2 db 0dh, 0ah, "Enter second number: $"
msgAns db 0dh, 0ah, 0dh, 0ah, "Answer: $"
msgEnd db 0dh, 0ah, 0dh, 0ah, "Press any key to finish", 0dh, 0ah, "$"
msgE0 db " [Unsupported Operation Exception]", 0dh, 0ah, "Retry operation ([+][-][*][/]): $"
opp db 2Bh
num1 dw 0000h
num2 dw 0000h
main PROC
mov ax, SEG msg
mov ds, ax
mov ah, 9
mov dx, OFFSET msg
int 21h
getNum1:
mov ah, 9
mov dx, OFFSET msgN1
int 21h
call readNum ;Gets a number and puts it in bx
mov bx,num1
mov ah, 9
mov dx, OFFSET msgO
int 21h
getOpp:
mov ah, 1
int 21h
mov bl, al
cmp bl, 2Ah ;* (ASCII 42)
je setOpp
cmp bl, 2Bh ;+ (ASCII 43)
je setOpp
cmp bl, 2Dh ;- (ASCII 45)
je setOpp
cmp bl, 2Fh ;/ (ASCII 47)
je setOpp
mov ah, 9 ;Anything else, display error and ask for the operator again
mov dx, OFFSET msgE0
int 21h
jmp getOpp
setOpp:
mov opp, bl
getNum2:
mov ah, 9
mov dx, OFFSET msgN2
int 21h
call readNum
mov num2, bx
mov ah, 9
mov dx, OFFSET msgAns
int 21h
showAns:
mov bx, num1 ;Display the first number entered
call disNum
mov ah, 6
mov dl, 20h ;Space
int 21h
mov dl, opp ;Display the operator
int 21h
mov dl, 20h ;Space
int 21h
mov bx, num2 ;Display the second number entered
call disNum
mov ah, 6
mov dl, 20h ;Space
int 21h
mov dl, 3Dh ;Equal sign
int 21h
mov dl, 20h ;Space
int 21h
mov bx, num1
mov ax, num2
mov dl, opp
call calc ;calc takes two numbers (bx, ax) and an ASCII operation (dl) and returns the answer in bx
call disNum ;Call straight away since the answer is in bx
cmp opp, 2Fh ;Was division used (there might be a remainder to show)
jne proEnd
cmp ax, 0000h ;Is remainder 0
je proEnd
mov bx, ax
mov ah, 6
mov dl, 20h ;Space
int 21h
mov dl, 72h ;r
int 21h
mov dl, 20h ;Space
int 21h
call disNum ;Show the remainder
proEnd:
mov ah,9
mov dx, OFFSET msgEnd
int 21h
mov ah, 1 ;Wait for user to press any key
int 21h
mov ah, 4ch
int 21h
main ENDP
;--------------------------------------------------------------------------------;
readNum PROC
.data
msgTry db 0dh, 0ah, "Please retry the number: $"
msgSE db " [Double Sign Exception]$"
msgBN db "Not A Digit Exception$"
sign db 00h ; The sign being used, 0 = +, 1 = -
signSet db 00h ;1 for set, this is used to stop sign being entered twice
wasErr db 00h ;If an error occurs, this is 1 so msgTry can be displayed
numIn dw 0000h
push ax ;This sub requires bx to pass the number back
push cx ;But everything else can be reserved
push dx
push si
push di
readNumS: ;Start
mov cx, 0000h
mov numIn, 0000h
mov sign, 00h
mov signSet, 00h
cmp wasErr, 00h ;If an error has not happened
je readNumG ;Get number
mov ah, 9 ;Else, ask for the number again
mov dx, OFFSET msgTry
int 21h
mov wasErr, 00h ;Reset error so it won't appear again (providing another error does not occur)
readNumG: ;Get
mov ah, 1
int 21h
mov bx, 0000h
mov bl, al
cmp bl, 2Bh ;+
je setSign
cmp bl, 2Dh ;-
je setSign
cmp bl, 0Dh ;Return
je readNumF
cmp bl, 30h ;0 (ASCII 48)
jl badNum
cmp bl, 39h ;9 (ASCII 57)
jg badNum
sub bl, 30h ;Turn into digit
mov dx, numIn
mov ax, dx
mov ch, 00h
readNumL: ;Loop ten times, moving all the digits in the current numIn 1 place forward (effectively * 10)
add ax, dx
inc ch
cmp ch, 9
jl readNumL
add ax, bx
mov numIn, ax
cmp cl, 03h ;Only allow 4 digit numbers
je readNumF
inc cl
jmp readNumG
setSign:
cmp cl, 00h ;Only can set a sign for the first input
jne badNum
cmp signSet, 01h ;Has the sign already been set
je signE
mov signSet, 01h
cmp bl, 2Bh ;+ is default, so carry on
je readNumG
mov sign, 01h
jmp readNumG
readNumF:
mov bx, numIn
cmp sign, 00h ;Using +
je readNumR ;Return now
neg bx ;If using -, turn the entered number into negative
readNumR:
pop di ;Returns all of the registers apart from bx to there original states
pop si
pop dx
pop cx
pop ax
ret
;Errors
signE: ;Two sign operators entered
mov ah, 9
mov dx, OFFSET msgSE
int 21h
mov wasErr, 01h
jmp readNumS
badNum: ;Digit was expected but not entered
mov ah, 9
mov dx, OFFSET msgBN
int 21h
mov wasErr, 01h
jmp readNumS
readNum ENDP
;--------------------------------------------------------------------------------;
calc PROC
.data
oppE db 0dh, 0ah, 0dh, 0ah, "[Unhandled Exception]", 0dh, 0ah, "Could not perform the calculation because the operator was not reconised", 0dh, 0ah, "The programme will now terminate", 0dh, 0ah, "$"
tooBigE db 0dh, 0ah, 0dh, 0ah, "[Overflow Exception]", 0dh, 0ah, "The answer is too big to store and display", 0dh, 0ah, "The programme will now terminate", 0dh, 0ah, "$"
divZeroE db 0dh, 0ah, 0dh, 0ah, "[Divide By Zero Exception]", 0dh, 0ah, "Can not divide by zero", 0dh, 0ah, "The programme will now terminate", 0dh, 0ah, "$"
calcM db 00h ;Is the number minus
calcAns dw 0000h
mov calcM, 00h
mov calcAns, 0000h
push cx ;BX = num1, AX = num2, DL = operation, the answer will be returned in BX
push si
push di
cmp dl, 2Bh ; +
je calcAdd
cmp dl, 2Dh ; -
je calcSub
cmp dl, 2Ah ; *
je calcMul
cmp dl, 2Fh ; /
je calcDiv
jmp calcOE ;Unreconised operation
calcAdd:
add bx, ax
jo calcTB ;If the answer is too big for the register (e.g. over 32,???) display error message
jmp calcRet
calcSub:
sub bx, ax
jo calcTB
jmp calcRet
calcMul:
mov dx, bx
mov bx, 0000h
cmp ax, 0000h
jge calcMulL ;Multiplying by positive number
neg ax ;Otherwise turn both the counter and copy of num1 into negative
neg dx ;So doing -num1 + -num2, which is the same as num1 - num2
calcMulL:
cmp ax, 0000h ;Keep looping while ax is greater then 0
jle calcRet
dec ax
add bx, dx
jo calcTB
jmp calcMulL
calcDiv:
cmp ax, 0000h ;Dividing by zero
je calcDZE
cmp bx, 0000h
jge calcDivP ;num1 is positive
cmp ax, 0000h
jge calcDivN ;num1 is negative, num2 is positive
neg bx
neg ax
jmp calcDivS
calcDivP: ;num1 is positive
cmp ax, 0000h
jge calcDivS ;num1 is positive, num2 is positive
mov calcM, 01h ;Remember to turn the answer into negative
neg ax
jmp calcDivS
calcDivN: ;num1 is negative, num2 is positive
mov calcM, 01h ;Remember to turn the answer into negative
neg bx
calcDivS:
mov dx, bx
mov bx, 0000h
calcDivL: ;Keep looping while num1 is larger then num2
cmp dx, ax
jl calcDivR ;Jump when a full subtract is no longer possible
inc bx ;How many full subtracts can be done
sub dx, ax
jo calcTB
jmp calcDivL
calcDivR:
mov ax, dx ;Store the remainder in ax, it is the calling programmes choce weather to use it
cmp calcM, 00h
je calcRet ;Return a positive number
neg bx
jmp calcRet ;Return a negative number
calcRet:
pop di
pop si
pop cx
ret
calcDZE:
mov ah, 9
mov dx, OFFSET divZeroE
int 21h
jmp calcEnd
calcTB:
mov ah, 9
mov dx, OFFSET tooBigE
int 21h
jmp calcEnd
calcOE:
mov ah, 9
mov dx, OFFSET oppE
int 21h
calcEnd:
mov ah, 4ch
int 21h
calc ENDP
;--------------------------------------------------------------------------------;
disNum PROC
.data
numOut dw 0000h
.code
mov numOut, bx
push ax
push bx
push cx
push dx
push si
push di
mov bx, numOut
cmp bx, 0000h
jge disNumF
mov ah, 6
mov dl, 2Dh
int 21h
neg bx
disNumF:
mov cl, 00h
cmp bx, 2710h
jge getTTho
cmp bx, 03E8h
jge getThou
cmp bx, 0064h
jge getHun
cmp bx, 000Ah
jge getTen
jmp disUnit
getTTho:
inc cl
sub bx, 2710h
cmp bx, 2710h
jge getTTho
disTTho:
add cl, 30h
mov ah, 6
mov dl, cl
int 21h
mov cl, 00h
cmp bx, 3E8h
jl disThou
getThou:
inc cl
sub bx, 3E8h
cmp bx, 3E8h
jge getThou
disThou:
add cl, 30h
mov ah, 6
mov dl, cl
int 21h
mov dl, 2Ch
int 21h
mov cl, 00h
cmp bx, 64h
jl disHun
getHun:
inc cl
sub bx, 64h
cmp bx, 64h
jge getHun
disHun:
add cl, 30h
mov ah, 6
mov dl, cl
int 21h
mov cl, 00h
cmp bx, 0Ah
jl disTen
getTen:
inc cl
sub bx, 0Ah
cmp bx, 0Ah
jge getTen
disTen:
add cl, 30h
mov ah, 6
mov dl, cl
int 21h
mov cl, 00h
cmp bx, 01h
jl disUnit
disUnit:
add bl, 30h
mov ah, 6
mov dl, bl
int 21h
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
disNum ENDP
END main