Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Write a program to
- ; (a) display a "?",
- ; (b) read two decimal digits whose sum "is less than 10
- ; (c) display them and their subtraction on the next line, with an appropriate message Simple Assembly Language Solution.
- .MODEL SMALL ; IN THIS COURSE ALL MODEL ARE SMALL
- .STACK 100H ; WE ALWAYS USE STACK 100H
- .DATA ; DATA SEGMENT
- STR1 DB 0AH,0DH,'THE SUBTRRACTION OF ' ; PRINT A NEW LINE AFTER TAKING INPUT SO WE USE 0AH,0DH
- FIRSTNUM DB ? ; TAKE A VARIABLE WHERE WE TAKE FIRST NUMBER
- STR2 DB ' AND ' ; ASSIGN A STRING IN STR 2
- SECONDNUM DB ? ; TAKING SENOCD NUMBER
- STR3 DB ' IS ' ; ASSIGN ANOTHER STRING IN STR3
- ANS DB ? ; TAKE A VARIABLE WHERE WE WILL PUT OUT SUMMATION, AND DO NOT END THE STRING BY $ SIGN
- STR4 DB ' $' ; ASSIGN $ HERE SO ALL AVOBE STRING ARE PRINT TOGETHER
- .CODE
- MAIN PROC ; MAIN CODE START HERE
- ;PROGRAMME SEGMENT PREFIX
- MOV AX,@DATA
- MOV DS,AX ; INITILATION OF DS
- MOV AH,2 ; PRINT SOME STRING
- MOV DL,3FH ; PRINT ? SIGN, WE CAN ALSO PRINT IT BY MOV DL,'?'
- INT 21H ; INTRUPT THE WORK
- MOV AH,1 ; TAKING SOME INPUT
- INT 21H ; INTRUPT THE WORK
- MOV BL,AL ; IF WE TAKE INPUT GENERALY GOES TO AL SO WE MOVE THE INPUT VALUE INTO BL.
- MOV FIRSTNUM,AL ; TAKE THE FIRST NUMBER INTO REGISTER
- INT 21H ; INTRUPT THE WORK
- MOV SECONDNUM,AL ; TAKE THE SECOND NUMBER INTO REGISTER
- SUB BL,AL ; HERE WE SUBTRACT BL AND AL
- ADD BL,30H ; TO COVERT ASCII TO DECIMAL WE ADDED 30 FROM SUBTRACT VALUE BL + 30 = BL , NOW IT IS DECIMAL.. CHECK ASCII TO UNDERSTAND BETTER
- MOV ANS,BL ; NOW MOVE THE VALUE INTO ANSWER
- MOV AH,9 ; PRINT STRING
- LEA DX,STR1 ; VARIABLE PRINTING FIRST TO LAST BECAUSE WE USE $ AT LAST. SO IT PRINT FIRST TO LAST
- INT 21H ; INTRUPT THE WORK
- MOV AX,4CH ; TERMINATED THE CODE AND EXIT
- INT 21H
- MAIN ENDP
- END MAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement