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 sum 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 SUM 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 AFTER PRINT THE ANSWER
- .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
- ADD BL,AL ; ADD BL AND AL
- SUB BL,30H ; TO COVERT ASCII TO DECIMAL WE SUBSTRACR 30 FROM SUMMATION 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