Advertisement
Nahid8195

Lab Test question 1

Oct 30th, 2021
2,956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; calculation of a+b-c
  2.  
  3. .MODEL SMALL   ; IN THIS COURSE ALL MODEL ARE SMALL
  4. .STACK 100H    ; WE ALWAYS USE STACK 100H
  5.  
  6.  
  7. .DATA     ; DATA SEGMENT
  8.    
  9.     SN_N1 DB "Enter first number: $"             ; we store the string here
  10.     SN_N2 DB 0DH,0AH,"Enter second number: $"    ; we store the string here
  11.     SN_N3 DB 0DH,0AH,"Enter third number: $"    ; we store the string here
  12.    
  13.     SN_STR1 DB 0AH,0DH,'CALCULATION OF '     ; PRINT A NEW LINE AFTER TAKING INPUT SO WE USE 0AH,0DH
  14.     SN_FIRSTNUM DB ?                      ; TAKE A VARIABLE WHERE WE TAKE FIRST NUMBER
  15.     SN_STR DB ","                          ; GIVE A COMMA (,) HERE
  16.     SN_SECONDNUM DB ?                     ; TAKE A VARIABLE WHERE WE TAKE SECOND NUMBER
  17.     SN_STR2 DB ' AND '                   ; ASSIGN A STRING IN STR 2
  18.     SN_THIRDNUM DB ?                    ; TAKING THIRD NUMBER
  19.     SN_STR3 DB ' IS '                    ; ASSIGN ANOTHER STRING IN STR3
  20.     SN_ANS DB ?                          ; TAKE A VARIABLE WHERE WE WILL PUT OUT SUMMATION, AND DO NOT END THE STRING BY $ SIGN
  21.     SN_STR4 DB ' $'                      ; ASSIGN $ HERE SO ALL AVOBE STRING ARE PRINT TOGETHER
  22.  
  23.  
  24.  
  25. .CODE
  26.  
  27. MAIN PROC       ; MAIN CODE START HERE
  28.    
  29.     ;PROGRAMME SEGMENT PREFIX
  30.     MOV AX,@DATA
  31.     MOV DS,AX    ; INITILATION OF DS
  32.                      
  33.     MOV AH,9        ; TO PRINT STRING WE USE IT
  34.     LEA DX,SN_N1     ; LOADED THE STRING          LEA = LOAD EFFICTIVE ADDRESS
  35.     INT 21H         ; THIS WILL PRINT THE LINE
  36.     MOV AH,1            ; TAKING SOME INPUT
  37.     INT 21H             ; INTRUPT THE WORK
  38.     MOV BL,AL           ; IF WE TAKE INPUT GENERALY GOES TO AL SO WE MOVE THE INPUT VALUE INTO BL
  39.     MOV SN_FIRSTNUM,AL  ; MOVE TO FIRSTNUMBER
  40.    
  41.    
  42.     MOV AH,9        ; TO PRINT STRING WE USE IT
  43.     LEA DX,SN_N2     ; LOADED THE STRING  
  44.     INT 21H         ; THIS WILL PRINT THE LINE
  45.     MOV AH,1            ; TAKING SOME INPUT
  46.     INT 21H             ; INTRUPT THE WORK
  47.     MOV CL,AL           ; IF WE TAKE INPUT GENERALY GOES TO AL SO WE MOVE THE INPUT VALUE INTO BL
  48.     MOV SN_SECONDNUM,AL    ; MOVE TO SECOND NUMBER
  49.      
  50.     MOV AH,9        ; TO PRINT STRING WE USE IT
  51.     LEA DX,SN_N2     ; LOADED THE STRING  
  52.     INT 21H         ; THIS WILL PRINT THE LINE
  53.     MOV AH,1             ; TO TAKE INPUT
  54.     INT 21H              ; TAKE THIRD NUMBER HERE
  55.     MOV SN_THIRDNUM,AL   ; MOVE THIRD NUMBER TO THIRDNUM VARIABLE
  56.    
  57.    
  58.     ADD BL,CL            ; ADD FIRST TWO NUMBER HERE
  59.     SUB BL,30H           ; CONVERT IT FROM ASCII TO INTEGER
  60.  
  61.     SUB BL,AL      ; HERE WE SUBTRACT BL AND AL
  62.     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
  63.     MOV SN_ANS,BL     ; NOW MOVE THE VALUE INTO ANSWER
  64.  
  65.     MOV AH,9      ; PRINT STRING
  66.     LEA DX,SN_STR1   ; VARIABLE PRINTING FIRST TO LAST  BECAUSE WE USE $ AT LAST. SO IT PRINT FIRST TO LAST
  67.     INT 21H       ; INTRUPT THE WORK                                  
  68.      
  69.      
  70.    
  71.     MOV AX,4CH ; TERMINATED THE CODE AND EXIT
  72.     INT 21H
  73.     MAIN ENDP
  74. END MAIN
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement