Statement: A set of 8 data are stored in memory location starting from F000H. Write a program to subtract two bytes at a time & store the result in same memory location with first byte replaced by the result of subtraction & second byte replaced with 01 H if result is in 2's complement otherwisee 00H
LXI H,F000 H
MVI B,04 H
NET:
MOV A,M
INX H
SUB M
JM MIN
DCX H
MOV M,A
MVI A,00 H
JMP NEXT
MIN:
DCX H
MOV M,A
MVI A,01 H
NEXT:
INX H
MOV M,A
INX H
DCR B
JNZ NET
HLT
Explanation:
Here we have given 8 data but we have to subtract 2 bytes at a time. So the loop should be executed 4 times as 4*2=8. Because of this register B is given the data 04 H.
Now first of all memory location is assigned to HL register pair. (NET loop)The data of memory location F000 H is copied in to accumulator. Then the memory address assigned to HL register pair is incremented by 1. After that the data stored in that memory location is subtracted from the data of accumulator. Result will be stored in accumulator. (A-M ->A)
If the result is negative(means if it is 2's complement) then the sign flag will be affected and loop MIN will be executed. Memory address of HL pair will be decremented the result of subtraction will be stored in memory location pointed by HL pair and 01 H data will be moved to accumulator. After that NEXT loop will be executed.
If the sign flag is not affected then memory address pointed by HL pair will be decremented by 1. The result will be stored in that memory location and accumulator will be stored with 00 H.
After that it will jump to NEXT loop.
In this loop first of all memory address will be incremented by 1 and the data of accumulator is moved to memory. Now you would think why we have done this right? Remember earlier the memory location of HL pair is decremented by 1. ( if it is executing first time then HL pair will be having F000 H and not the F001 H so in this loop first we will make it to F001 H understood??)
Then again it will incremented by 1 (for our example here it will become F003 H) Then the value of register B will be decremented if it is not zero then NET loop will be executed again.
HLT stands for 'stop'. :-)
Sunday, April 11, 2010
Wednesday, April 7, 2010
Statement: A set of memory is stored in memory locations starting from F000H & the last reading is the set is FFH. Write an ALP to check each byte in the string & save the bytes in the reange of (100)d to (150)d (both inclusive) in memory location starting from F020 H. Also store in memory location F01F H the number of bytes accepted from the given set which lies within given range.
LXI H,F000H
LXI B,F020H
NXT:
MOV A,M
CPI FF
JZ END
CPI 63H
JC END1
CPI 97H
JNC END1
STAX B
INX B
INR D
END1:
INX H
JMP NXT
END:
LXI H,F01FH
MOV M,D
HLT.
Explanation:
In this program, the last reading is FF H so first of all we will compare the data with FF. So when the data will be FF H it will give zero as a result and it will jump to the END loop.
The other thing which is given is the range! It is 100 to 150 in decimal. So in HEX it is 64 H to 96 H. But it also says that 100 and 150 are included. So for comparison our range will be 63 H to 97 H so that if the data is 64 H or 96 H, it will execute the loop.
The data which is stored in accumulator is compared with 63 H, if the data is smaller then 63 H it will jump to the END loop. If data is bigger then 63 H then it will be compared with 97 H. If the data is greater then 97 H then END loop will be executed. Otherwise the content of accumulator will be stored in BC register pair. Then the memory location of BC register pair is incremented and the content of register D is also incremented. After that the memory location of HL register pair is incremented and the NXT loop will be executed again.
When the data is FF H , the END loop is executed that means F01F memory location is assigned by HL register pair. The data of register D is moved to the memory location F01F H.( it will give the number of how many times NXT loop is executed.)
HLT stands for 'Stop'.
LXI H,F000H
LXI B,F020H
NXT:
MOV A,M
CPI FF
JZ END
CPI 63H
JC END1
CPI 97H
JNC END1
STAX B
INX B
INR D
END1:
INX H
JMP NXT
END:
LXI H,F01FH
MOV M,D
HLT.
Explanation:
In this program, the last reading is FF H so first of all we will compare the data with FF. So when the data will be FF H it will give zero as a result and it will jump to the END loop.
The other thing which is given is the range! It is 100 to 150 in decimal. So in HEX it is 64 H to 96 H. But it also says that 100 and 150 are included. So for comparison our range will be 63 H to 97 H so that if the data is 64 H or 96 H, it will execute the loop.
The data which is stored in accumulator is compared with 63 H, if the data is smaller then 63 H it will jump to the END loop. If data is bigger then 63 H then it will be compared with 97 H. If the data is greater then 97 H then END loop will be executed. Otherwise the content of accumulator will be stored in BC register pair. Then the memory location of BC register pair is incremented and the content of register D is also incremented. After that the memory location of HL register pair is incremented and the NXT loop will be executed again.
When the data is FF H , the END loop is executed that means F01F memory location is assigned by HL register pair. The data of register D is moved to the memory location F01F H.( it will give the number of how many times NXT loop is executed.)
HLT stands for 'Stop'.
Monday, April 5, 2010
Statement: A two 16 bit data are stored in consecutive memory location starting from F000H with lower bytes stored first.Write an ALP to copy this data in four consecutive memory location starting from E000H
LXI H,1221H (it can be any number)
LXI D,2211H
SHLD F000H
XCHG
SHLD F002H
XCHG
SHLD E000H
XCHG
SHLD E002H
HLT
LXI H,1221H (it can be any number)
LXI D,2211H
SHLD F000H
XCHG
SHLD F002H
XCHG
SHLD E000H
XCHG
SHLD E002H
HLT
Subscribe to:
Posts (Atom)