Assembly Answers For Understanding
Assembly Answers For Understanding
Solution:
PROGRAM:
START: LXI H, 2061 H ; HL = 2060 H : Point to Source address .
LXI D, 2080 H ; DE = 2080 H: Destination address.
MVI B, 05 H ; Counter for 5 temperature readings
NEXT: MOV A,M ; Get Reading: Load reading from source address HL to A
STAX D ; Store A at Destination Address
INX H ; Go to Next Source Address
INX H ;Go to next source address (Skip High Order of next Temp
Reading as given in question that it remains constant)
INX D ; Go to next Destination Address
DCR B ;Decrement Counter
JNZ NEXT ;If counter not zero Jump to NEXT and transfer the values
again.
HLT
Detailed Explanation:
The source address, where readings are stored starts at XX60H, Let us assume
XX=20. We get source address 2060H. Now, we use LXI H, 2061H to point to
source address, HL register Pair.
Now, these temperature values need to be transferred to memory location
XX80H. We use LXI D, 2080H to point to destination address , DE pair.
We have 5 temperature values, therefore we need to transfer values 5 times. To
count this we use MVI B, 05 H to set a counter at register B with value 5.
Inside NEXT:
Pick up value from source address i.e HL register pair and store it in A. We use
MOV A, M. to carry out this task.
Value stored at A, need to be transferred to Destination address at DL register
pair. Use STAX D to store value from A to DL register Pair.
Move to next source address to get next value. Increment the memory address
using INC H.
Increment again, INC H to skip High order as given in question that it is constant.
Increment the destination memory location to store value at next memory location
using INC D.
Now, one value has been transferred, Decrement the counter by 1 using DCR B.
If the counter value is not zero it means there are more values that need to be
transferred therefore, if NOT ZERO JUMP to NEXT. JNZ NEXT and repeat the
above steps inside NEXT to transfer rest of the temperature values.
When Counter B becomes zero, it means all the values have been transferred; the
program will not jump to NEXT and will stop, HLT.
================================================================
SOLUTION:
PROGRAM:
START: LXI D, 2050 H ; Pointer for readings of Furnace 1
LXI H, 2060 H ; Pointer for readings of furnace 2
MVI C, 05 H ; Counter for 5 readings
NEXT: LDAX D ; Storing reading from furnace 1 to A
MOV B,M ; Storing reading from furnace 2 in B
SUB B ; Subtract B from A,
JC SHUTDOWN ; If there is carry from (A-B) it means(B > A) i.e.
temperature in furnace 2 > temperature in furnace 1,
Go to shutdown and display emergency.
INX D ; Go to next address for furnace 1
INX H ;Go to next address for furnace 2
DCR C ;Decrement Counter
JNZ NEXT ;If counter is not zero, go to next and take readings
again
MVI A, 01H ; Set Bit D0=1
OUT PORT 1 ;Turn on Bit D0 and display content of A on Port1
HLT
SHUTDOW MVI A, 0FFH ;Load emergency indicator
N
OUT PORT 1 ;Display content of A (Here, Emergency) on PORT1
HLT
Detailed Explanation:
The question statement wants to compare two sets of readings stored at different
value. If the particular value of set 1 is greater than corresponding value of set 2
then D0 bit of PORT1 has to be turned on otherwise, emergency signal FF has to
be displayed at port1.
Now let us take look at steps of the program.
Given furnace 1 readings are stored at memory address XX50H and
furnace two readings are stored at memory address XX60H. Let XX=20
We use LXI D, 2050H, to point to set of readings of Furnace 1
LXI H, 2060H, to point to set of readings of Furnace 2.
Given, there are 5 readings therefore to compare the readings 5 times we
set up counter at C with value 05H using MVI C,05H.
Inside NEXT:
LDAX D, loads the accumulator with value from register pair DL, here it
is storing temperature values of Furnace 1. Therefore, LDAX D, loads the
value of temperature of furnace 1 in accumulator.
MOV B, M moves the value of HL pair to register B. Note, HL pair is
storing values of set of furnace 2. Therefore this instruction loads the B
with temperature value of Furnace 2.
SUB B, To compare the values of furnace 1 and furnace 2, we subtracted
B from A i.e. Value of furnace 2 from furnace 1. If A>B then no carry will
be generated but if B>A then carry will be generated.
If carry is generated it means B>A. i.e. Temperature value of Furnace 2 is
greater than Furnace 1. Now according to question if this happens the
process needs to stop and emergency signal should be generated at
PORT1. Therefore we use, JC SHUTDOWN. Which will jump to
SHUTDOWN section if the carry is generated.
If A>B, it means no carry is generated and temperature value at furnace 1
> furnace 2. We will move on to check the next values. Therefore, we will
increment the memory locations.
Using INC D and INC H. Note: INC D will increment the DE pair(Furnace
1) and INC H will increment HL pair (Furnace 2).
3. Specify the contents of the accumulator and the status of the Cy flag
when the following instructions are executed
a. MVI A,B7H
ORA A
RLC
SOLUTION:
Explanation:
MVI A, B7H:
Moves the value B7H to the accumulator.
ORA A:
OR the value of A with A.
We have B7 at A:
B7 in binary : 10110111
A OR A: 10110111 OR 10110111 : 10110111
RLC:
Rotate left accumulator, This mnemonic rotates the value stored at
accumulator to the left by 1 bit. Carry flag is not involved in rotation.
We have:
A : 10110111
Rotating each bit to left:
01101111
In Hexa: 01101111 -> 6FH
Carry flag is set.
b. MVI A,B7H
ORA A
RAL
SOLUTION:
Accumulator (A): 6EH
Carry Flag (CY): 1
Explanation:
MVI A, B7H:
Moves the value B7H to the accumulator.
ORA A:
OR the value of A with A.
We have B7 at A:
B7 in binary : 10110111
A OR A: 10110111 OR 10110111 : 10110111
RAL:
Rotate accumulator left , This mnemonic rotates the value stored at
accumulator to the left by 1 bit. Carry flag is involved in rotation.
We have:
A : 10110111
Rotating each bit to left:
CY-1 01101110
In Hexa: 01101110 -> 6EH
Carry flag is set.
SOLUTION:
Before rotate instruction: 24
After Rotate Instruction: 48
Mathematical Function: Multiply by 2
Explanation:
MVI A, 18H:
Moves value 18H to A
18H in Binary: 00011000
00011000 in Decimal: 24
RLC:
Rotates the accumulator value to left by 1 bit. Without involving
carry.
Rotate 00011000 to left by 1 bit:
00110000
00110000 in Decimal: 48
From above we can deduce that after RLC the value in the
accumulator is multiplied by 2.
b. MVI A,78H
RRC
RRC
SOLUTION:
Before rotate instruction: 120
After Rotate Instruction: 30
Mathematical Function: Divide By 4
Explanation:
MVI A, 78H:
Moves value 78H to A
78H in Binary: 01111000
01111000 in Decimal: 120
RRC:
Rotates Righ Accumulator, It rotates the accumulator value to right by
1 bit. Involving carry.
Rotate 01111000 to right by 1 bit:
00111100
00111100 in Decimal: 60
RRC:
It again rotates the bit value of A to right by 1 bit.
Rotating 00111100 to right by 1 bit:
00011110
00011110 in Decimal: 30
From above we can deduce that two RRC instructions divided the
original value by 4.
5. Explain the mathematical function that is performed by the following
instructions
MVI A,07H
RLC
MOV B,A
RLC
RLC
ADD B
SOLUTION:
Multiply By 10
Explanation:
MVI A, 07H:
Moves the value 07H to the Accumulator.
07H in Binary: 0000 0111
In decimal: 7
RLC:
Rotates the bit value of A to left by 1 bit position by not involving
carry.
Rotates 0000 0111 to right by 1 bit:
0000 1110
MOV B, A:
Moves value of A to B:
B← A
B← 0EH : 0000 1110
RLC:
Rotates the bit value of A to left by 1 bit position.
Rotates 0001 1100 to left by 1 bit:
0001 1100
RLC:
Again rotates the bit value of A to left by 1 bit position.
Rotates 0001 1100 to left by 1 bit:
0011 1000
ADD B:
Add B to the content of accumulator.
A: 0011 1000
B: 0000 1110
0011 1000
+ 0000 1110
0100 0110
In A: 0100 0110
In decimal: 70
Therefore, It can be observed that given set of instructions
multiplied the decimal value in the beginning by 10.
SOLUTION:
Detailed Explanation:
Point to the address where given readings are stored. It is given that
readings are stored starting at XX50H. Let XX=20.
We use LXI H, 2050H. To point to address of readings.
Store the byte to be found at memory location. We have byte to be
found = 40H, we stored it in Register D using MVI D,40H
There are 8 values therefore we will be checking 8 times. For this we
set the counter by storing 8 in register C. MVI C, 08H.
Inside NEXT:
Get the first byte data from the source memory location and store it in
A for comparison. MVI A, M. [Here, M is Source memory location].
Compare the value stored at A with the value that is to be checked and
is stored in register D. CMP D: Compares value of A with D.
If the value at A = Value at D then CMP D will set Zero flag: 1
JZ Display: This will Jump to DISPLAY section if 40H is found in
the set.
If the zero flag is not set it means the current value at A is not equal to
D. and we will increment the source address to get next value: INC H
Decrement the counter: DCR C
JNZ NEXT: Check if after decrementing the value is non zero. If it is
non zero it means there are more values to be compared and the
execution jumps to NEXT to compare more values.
If the counter becomes Zero, It means all the values have been
checked and 40H is not found in the set. In this condition, according to
the question FFH is to be output.
MVI A FFH: Moves FFH to the A.
OUT PORT1: Output value of A, here it is FFH to the PORT1.
Stop the execution using HLT
Inside DISPLAY
It is executed if 40H is found in the set.
MOV A, H: It moves the Higher address value of location where 40H
is found to A.
OUT PORT1: Outputs the content of A to port1, here the higher
address value of the location of 40H is output to PORT1.
MOV A,L: It moves the lower address value of location of 40H to A.
OUT PORT2: Outputs the lower address value of location of 40H to
PORT2.
SOLUTION:
Number of Bytes that are added by Program: 256
SOLUTION:
Memory Locations where result is stored: 2090H – 2091H
SOLUTION:
ERROR 1: A not initialized to 00
ERROR 2: INX H is missing in the loop