51.9k views
5 votes
Write an ALP to find cube of N 8-bit numbers in an array using 8086:

User Soywod
by
7.6k points

1 Answer

4 votes

ALP for cube of N 8 bit numbers in an array using 8086 is described below.

Step-by-step explanation:

To solve this problem, we are taking the size of the array into the CL register, and make CH = 00H for counting. Now from each location take the number into accumulator, to make cube, we have to multiply it three times. so we are storing the number temporarily into another register, then multiply AL with AL, and then AL and the value again from that stored location. Thus the cube is generated. After that it is again stored into memory location.

Input Memory Address (Offset)

04 500

03 501

01 502

02 503

05 504

Algorithm –

  • Store 500 to SI and Load data from offset 500 to register CL and set register CH to 00 (for count).
  • Increase the value of SI by 1.
  • Load number(value) from offset SI to register AL.
  • Move the value of register AL to BL.
  • Multiply the value in register AL by itself.
  • Multiply the value in register AL by BL.
  • Store the result (value of register AL ) to memory offset SI.
  • Increase the value of SI by 1.
  • Loop above 6 till register CX gets 0.

MEMORY MNEMONICS COMMENT

ADDRESS

400 MOV SI, 500 SI<-500

403 MOV CL, [SI] CL<-[SI]

405 MOV CH, 00 CH<-00

407 INC SI SI<-SI+1

408 MOV AL, [SI] AL<-[SI]

40A MOV BL, AL BL<-AL

40C MUL AL AX=AL*AL

40E MUL BL AX=AL*BL

410 MOV [SI], AL AL->[SI]

412 INC SI SI<-SI+1

413 LOOP 408 JUMP TO 408 IF CX!=0 and CX=CX-1

415 HLT end

Explanation –

  • MOV SI, 500: set the value of SI to 500
  • 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
  • MOV BL, AL: move value of register AL to BL.
  • MUL AL: multiply value of register AL by AL.
  • MUL BL: multiply value of register AL by BL.
  • MOV [SI], AL: store value of register AL at offset SI.
  • INC SI: increase value of SI by 1.
  • LOOP 408: jump to address 408 if CX not 0 and CX=CX-1.
  • HLT: stop
User Lechnerio
by
7.2k points