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'.

No comments:

Post a Comment