0% found this document useful (1 vote)
71 views

Examples

This document contains several examples of assembly language code segments and questions about their purpose and output. The first example initializes various 8-bit registers with values and performs addition, AND, and subtraction operations between them. The second performs an arithmetic right shift on a 8-bit register. The third provides two methods to add the contents of register AL to register BX. The fourth gives answers to swapping the contents of registers AX and BX using various methods. The fifth traces a program that uses XOR, ADD, CMP and LOOP to sum the values from 0 to 15.

Uploaded by

Mohamed Nabil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
71 views

Examples

This document contains several examples of assembly language code segments and questions about their purpose and output. The first example initializes various 8-bit registers with values and performs addition, AND, and subtraction operations between them. The second performs an arithmetic right shift on a 8-bit register. The third provides two methods to add the contents of register AL to register BX. The fourth gives answers to swapping the contents of registers AX and BX using various methods. The fifth traces a program that uses XOR, ADD, CMP and LOOP to sum the values from 0 to 15.

Uploaded by

Mohamed Nabil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Examples:

The 8-bit registers AL, BL, CH, and DH initially have the following values:
AL= 11110010
BL =11111111
CH =10111001
DH =11101010
Determine the 8-bit values in each register after the execution of the following
sequence of micro-operations.
AL + BL (add) Add BR to AR
cH and DH, BL + 1 (inc) AND DR to CR, increment BR
AL- CH (sub) Subtract CR from AR.

2-
An 8-bit register contains the binary value 10011100. What is th~ register value after an
arithmetic shift right? Starting from the initial number 10011100, determine the register value
after an arithmetic shift left, and state whether there is an overflow.
3-
write two methods by which we can add the contents of register AL to that register BX.
Answer: 1)
PUSH AX
MOV AH,0
ADD BX,AX
POP AX
2) ADD BL,AL
ADC BH,0

4-
Write an assembly code that swap the contents of two registers AX, BX.
a. Using third register.
b. Using The Stack.
c. Using ADD, SUB and NEG.
d. Using XOR.

Answers :

a. Using CX to swap content of AX and BX

MOV CX,AX
MOV AX,BX
MOV BX,CX

b. Using stack

PUSH AX
PUSH BX
POP AX
POP BX

c. Using ADD,SUB , and NEG

ADD AX,BX
SUB BX,AX
NEG BX
SUB AX,BX

d. Using XOR

XOR AX,BX
XOR BX,AX
XOR AX,BX
5-
Trace the following program where N=16. What is the purpose of the program (7
th
2010):
XOR AX,AX
MOV CX,N
Again: ADD AX,CX
CMP CX,S
JLE XX
DEC CX
DEC CX
LOOP Again
xx:
Answer:
AX CX CMP CX,5
JLE XX
AH AL CH CL
XOR AX,AX 00 00 -- --
MOV CX,N 00 00 00 10
ITERATION 1 00 10 00 0D FALSE, NO JMP
ITERATION 2 00 1D 00 0A FALSE, NO JMP
ITERATION 3 00 27 00 07 FALSE, NO JMP
ITERATION 4 00 2E 00 04 FALSE, NO JMP
ITERATION 5 00 32 00 04 TRUE, JMP TO XX

Purpose of the program is summing values of 10 H, 0D H, 0A H, 07 H, 04 H then
store result in AX register

You might also like