Codes
find out the largest among 8-bit n numbers, where size “10" is
stored at memory address 2000 : 600 and the numbers are stored from
memory address 2000 : 601 and store the result (largest number)
into memory address 2000 : 800.
Example
Input data and memory address
| 10 |
20 |
21 |
22 |
23 |
24 |
25 |
36 |
26 |
27 |
28 |
| 600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
607 |
608 |
Out put data
Algorithm –
- Load data from offset 600 to register CL and set register CH to
00 (for count).
- Load first number(value) from next offset (i.e 601) to register
AL and decrease count by 1.
- Now compare value of register AL from data(value) at next
offset, if that data is greater than value of register AL then
update value of register AL to that data else no change, and
increase offset value for next comparison and decrease count by 1
and continue this till count (value of register CX) becomes 0.
- Store the result (value of register AL ) to memory address 2000
: 800.
Program
| MEMORY ADDRESS |
MNEMONICS |
COMMENT |
| 500 |
MOV SI, 600 |
SI<-600 |
| 503 |
MOV CL, [SI] |
CL<-[SI] |
| 505 |
MOV CH, 00 |
CH<-00 |
| 507 |
INC SI |
SI<-SI+1 |
| 508 |
MOV AL, [SI] |
AL<-[SI] |
| 50A |
DEC CL |
CL<-CL-1 |
| 50C |
INC SI |
SI<-SI+1 |
| 50D |
CMP AL, [SI] |
AL-[SI] |
| 50F |
JNC 513 |
JUMP TO 513 IF CY=0 |
| 511 |
MOV AL, [SI] |
AL<-[SI] |
| 513 |
INC SI |
SI<-SI+1 |
| 514 |
LOOP 50D |
CX<-CX-1 & JUMP TO 50D IF CX NOT 0 |
| 516 |
MOV [800], AL |
AL->[800] |
| 51A |
HLT |
END |
Explanation –
- MOV SI, 600 : set the value of SI to 600
- MOV CL, [SI] : load data from offset SI to
register CL
- MOV CH, 00 : set value of register CH to
00
- INC SI : increase value of SI by 1.
- MOV AL, [SI] : load value from offset SI to
register AL
- DEC CL : decrease value of register CL by
1
- INC SI : increase value of SI by 1
- CMP AL, [SI] : compares value of register AL
and [SI] (AL-[SI])
- JNC 513 : jump to address 513 if carry not
generated
- MOV AL, [SI] : transfer data at offset SI to
register AL
- INC SI : increase value of SI by 1
- LOOP 50C : decrease value of register CX by 1
and jump to address 50D if value of register CX is not zero
- MOV [800], AL : store the value of register AL
to offset 800
- HLT : stop