successive loop in Assembly [closed]

0

I'm studying Assembly but I'm having a hard time, I have to solve an exercise, but I did not understand what to do.

"Loop for successive subtractions until negative. load, sub."

Someone can help me.

    
asked by anonymous 04.04.2018 / 00:15

1 answer

0

Using the MOV of the x86 instruction set you can retrieve a word (WORD, 2 bytes) memory from an address. We assume that in the 0200 and 0201 address the value for AX is stored, and 0202 and 0203 is stored the value for BX.

 072C:0100     MOV AX,[0200]
 072C:0103     MOV BX,[0202]

See that I have incremented two positions since AX is a two-byte WORD. You can initialize the addresses with mov also, for example:

MOV WORD PTR [0200],0005
MOV WORD PTR [0202],0002

The result at address 0200 will be:

Being

020005020100020202020300

Rememberthattheorderisalwaysreversedbutwhenretrievingthedatawithmovthegivenbackcorrectlyas:

bytebyteword02010200->000502030202->0002

ThefollowingcodeistoperformthesuccessiveLOOPbysubtractingbothvariablesinAXeBX,beingAX-BX,thenBX<AX,continuingataddress0107

072C:0107SUBAX,0001072C:010ASUBBX,0001072C:010DJNZ107072C:010FINT20

WhileBXisnon-zero,thatis,ifFLAGZERO(whichindicatesthatthelastoperationresultedinzero)isfalse,theflowreturnstotheaddress0107SUBAX.

Followingisthefinalcodefortheprogram

Terminating the INT 20 interrupt with the call, to return control of the program to the operating system, and preventing the program from running garbage.

Note

Here I used SUB , but you could use DEC , since you only decrement only 1 always. And the LOAD statement does not exist in x86, but there are LODSB or LODSW , which are more complex, and are used for STRING (data array) operations.

I'm using the MS-DOS debug program to debug. It also works with SYMDEB.EXE as well.

If used in another high-level language such as C, or pascal, you can use label: before the loop and JNZ @label instead of JNZ 0107 .

    
04.04.2018 / 04:16