Advertisement
Nahid8195

LAB 3 (Take two input and print the two digit and their subtraction)

Oct 24th, 2021
3,406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Write a program to
  2.  ; (a) display a "?",
  3.  ; (b) read two decimal digits whose sum "is less than 10
  4.  ; (c) display them and their subtraction on the next line, with an appropriate message Simple Assembly Language Solution.
  5.        
  6.  
  7.  
  8. .MODEL SMALL   ; IN THIS COURSE ALL MODEL ARE SMALL
  9. .STACK 100H    ; WE ALWAYS USE STACK 100H
  10.  
  11.  
  12. .DATA     ; DATA SEGMENT
  13.    
  14.     STR1 DB 0AH,0DH,'THE SUBTRRACTION OF '     ; PRINT A NEW LINE AFTER TAKING INPUT SO WE USE 0AH,0DH
  15.     FIRSTNUM DB ?                     ; TAKE A VARIABLE WHERE WE TAKE FIRST NUMBER
  16.     STR2 DB ' AND '                   ; ASSIGN A STRING IN STR 2
  17.     SECONDNUM DB ?                    ; TAKING SENOCD NUMBER
  18.     STR3 DB ' IS '                    ; ASSIGN ANOTHER STRING IN STR3
  19.     ANS DB ?                          ; TAKE A VARIABLE WHERE WE WILL PUT OUT SUMMATION, AND DO NOT END THE STRING BY $ SIGN
  20.     STR4 DB ' $'                      ; ASSIGN $ HERE SO ALL AVOBE STRING ARE PRINT TOGETHER
  21.  
  22.  
  23.  
  24. .CODE
  25.  
  26. MAIN PROC       ; MAIN CODE START HERE
  27.    
  28.     ;PROGRAMME SEGMENT PREFIX
  29.     MOV AX,@DATA
  30.     MOV DS,AX    ; INITILATION OF DS
  31.    
  32.                                                
  33.     MOV AH,2     ; PRINT SOME STRING
  34.     MOV DL,3FH   ; PRINT ? SIGN, WE CAN ALSO PRINT IT BY       MOV DL,'?'
  35.     INT 21H      ; INTRUPT THE WORK
  36.  
  37.     MOV AH,1            ; TAKING SOME INPUT
  38.     INT 21H             ; INTRUPT THE WORK
  39.     MOV BL,AL           ; IF WE TAKE INPUT GENERALY GOES TO AL SO WE MOVE THE INPUT VALUE INTO BL.  
  40.     MOV FIRSTNUM,AL     ; TAKE THE FIRST NUMBER INTO REGISTER
  41.     INT 21H             ; INTRUPT THE WORK
  42.     MOV SECONDNUM,AL    ; TAKE THE SECOND NUMBER INTO REGISTER
  43.  
  44.     SUB BL,AL      ; HERE WE SUBTRACT BL AND AL
  45.     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
  46.     MOV ANS,BL     ; NOW MOVE THE VALUE INTO ANSWER
  47.  
  48.     MOV AH,9      ; PRINT STRING
  49.     LEA DX,STR1   ; VARIABLE PRINTING FIRST TO LAST  BECAUSE WE USE $ AT LAST. SO IT PRINT FIRST TO LAST
  50.     INT 21H       ; INTRUPT THE WORK                                  
  51.      
  52.      
  53.    
  54.     MOV AX,4CH ; TERMINATED THE CODE AND EXIT
  55.     INT 21H
  56.     MAIN ENDP
  57. END MAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement