0% found this document useful (0 votes)
21 views18 pages

Exp 2

Uploaded by

anas1054108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views18 pages

Exp 2

Uploaded by

anas1054108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Registers

Registers are high-speed storage locations directly inside the CPU, designed to
be accessed at much higher speed than conventional memory.
Types of registers
• General purpose Registers
• Segment Registers
• Status Flags Register
• Instruction Pointer
General Purpose Register: Can be divided into Data and Index
Data Registers: Are used for arithmetic and data movement
• AX (Accumulator register) -> perform operations
• BX (Base Register) -> Address
• CX (Counter Register) -> Loop
• DX (Data Register) -> Data Storage
Index Register: Contains the offsets of data and instructions.
• BP (Base pointer Register)
• SP (Stack pointer Register)
• SI (Source Index Register)
• DI (Destination Index Register)
OPCODE OPERAND EXPLANATION EXAMPLE
ADD D, S D=D+S ADD AX, [2050]
D = D + S + prev.
ADC D, S ADC AX, BX
carry
SUB D, S D=D–S SUB AX, [SI]
D = D – S – prev.
SBB D, S SBB [2050], 0050
carry
AX = AL * 8-bit
MUL 8-bit register MUL BH
reg.
DX AX = AX * 16-
MUL 16-bit register MUL CX
bit reg.
AX = AX / 8-bit
reg. ; AL =
DIV 8-bit register DIV BL
quotient ; AH =
remainder
DX AX / 16-bit
reg. ; AX =
DIV 16-bit register DIV CX
quotient ; DX =
remainder
;8+4-2+3

.code
add ax,bx
main proc
mov ax,8 sub ax,cx
mov bx,4
mov cx,2 add ax,dx
mov dx,3
hlt
main endp

end main
.exit
Practice (Addition)
org 100h ; Start at offset 100h for .COM file compatibility
; Define variables
num1 db 10h ; First number (hexadecimal 10 = decimal 16)
num2 db 05h ; Second number (hexadecimal 05 = decimal 5)
add_result db ? ; Storage for addition result
sub_result db ? ; Storage for subtraction result
start:
; Addition
mov al, num1 ; Load num1 into AL
add al, num2 ; Add num2 to AL
mov add_result, al ; Store addition result in add_result
; Exit program
mov ax, 4C00h
int 21h
Practice (Subtraction)
org 100h ; Start at offset 100h for .COM file compatibility
; Define variables
num1 db 10h ; First number (hexadecimal 10 = decimal 16)
num2 db 05h ; Second number (hexadecimal 05 = decimal 5)
add_result db ? ; Storage for addition result
sub_result db ? ; Storage for subtraction result
start:
; Subtraction
mov al, num1 ; Reload num1 into AL
sub al, num2 ; Subtract num2 from AL
mov sub_result, al ; Store subtraction result in sub_result
; Exit program
mov ax, 4C00h
int 21h
Practice (Multiplication)
org 100h ; Start at offset 100h for .COM file compatibility
; Define variables
num1 db 4 ; First number (4)
num2 db 3 ; Second number (3)
result dw ? ; Storage for 16-bit result (since 8-bit * 8-bit = 16-bit result)
start:
; Load first number into AL
mov al, num1 ; Move num1 (4) into AL
; Perform unsigned multiplication with num2
mov bl, num2 ; Move num2 (3) into BL
mul bl ; Multiply AL by BL (AL * BL). Result is in AX.
Practice (Division)
org 100h ; Start at offset 100h for .COM file compatibility

; Define variables
num1 db 20 ; Dividend (20 in decimal)
num2 db 6 ; Divisor (6 in decimal)
quotient db ? ; Storage for quotient
remainder db ? ; Storage for remainder

start:
; Load the dividend into AX (AL for 8-bit operations)
mov al, num1 ; Move the value of num1 (20) into AL
Tasks:
1. Write a program in assembly language that calculates the square of
six by adding six to the accumulator six times.
2. Write a program to solve the following equation
DX = AX + BH – CL + DX
Initialize AX, BH, CL, DX registers with 0100h, 55ABh, 0A11h, and
0001h values respectively.

You might also like