Practical No. 3: Write an assembly language program to perform addition and subtraction of two 8 and 16-bit numbers

PROGRAM TO ADD 2 8BIT NUMBER

Code:

; PROGRAM TO ADD 2 8BIT NUMBER

.MODEL SMALL
.STACK 100

My_Data SEGMENT

  NUM1 DB 80
  NUM2 DB 32
  RES  DB ?

My_Data ENDS

My_Code SEGMENT

  ASSUME CS:My_Code,DS:My_Data

  MOV AX,My_Data ; TAKING BASE ADDRESS OF DATA DIRECTIVE INTO CODE DIRECTIVE
  MOV DS,AX    ; PUTTING DATA DIRECTIVE ON HEAP MEMORY
               ; SO THAT VARIABLE CAN ACCESS DIRECTLY

  MOV AL,NUM1  ; COPYING DATA CONTAIN TO REGISTER
  MOV BL,NUM2

  ADD AL,BL   ; ADDING CONTAIN OF BL INTO AL

  MOV RES,AL
  MOV DL,RES

  MOV AH,2  ; SERVICE ROUTINE TO PRINT CONTAIN OF DX
  INT 21H

  MOV AH,4CH  ; EXIT
  INT 21H

My_Code ENDS



END

Another way Program Screen Shot:





Output:  


PROGRAM TO SUBTRACT 2 8 BIT NUMBER

Code:



.MODEL SMALL
.STACK 100

.DATA
    NUM1 DB 70
    NUM2 DB 5
    RES  DB ?
.CODE
    MOV AX,@DATA
    MOV DS,AX

    MOV AL,NUM1
    MOV BL,NUM2

    SUB AL,BL

    MOV RES,AL
    MOV DL,AL

    MOV AH,2
    INT 21H

    MOV AH,4CH
    INT 21H
END


Ouput:




Previous
Next Post »

1 Comments:

Click here for Comments
Unknown
admin
May 31, 2021 at 9:41 AM ×

It's nice

Thank You Unknown For Comment.
Reply
avatar