.pos 0x200
.align 4
InputArray:
.long 5
.long 10
Done: .long 0x0
.pos 0x400
.align 4
OutputArray:
.pos 0x0
irmovl InputArray,%eax
irmovl OutputArray, %esi
Loop:
mrmovl (%eax), %ecx # get first element from InputArray
mrmovl (%eax), %edi # a copy of first element used for multiplication
irmovl $4, %ebx # increment the pointer of InputArray
addl %ebx, %eax
mrmovl (%eax), %edx # get second element from InputArray
irmovl $1, %ebx # add first element to its copy for the amount of second element
subl %ebx, %edx
jg mult
rmmovl %ecx,(%esi) # output value to OutputArray
mult:
addl %edi, %ecx
subl %ebx, %edx
jg mult
Exit: halt
This is a really simple program that does unsigned mutiplication of a pair of integers (5 times 10) I wrote for Y86.
When I run the code, the result looks like this:
Stopped in 38 steps at PC = 0x42. Status 'HLT', CC Z=1 S=0 O=0
Changes to registers:
%eax: 0x00000000 0x00000204
%ecx: 0x00000000 0x00000032
%ebx: 0x00000000 0x00000001
%esi: 0x00000000 0x00000400
%edi: 0x00000000 0x00000005
Changes to memory:
The register ecx for the result of calculation is 32 in hex so I definitely know that the mult loop has performed as intended, but nothing is being output into OutputArray which I don't understand why.
I am not sure if I understand what you mean by "No code is supposed to be after a jump statement in a label and the correct alternative was to locate the subsequent code in another label and use another jump statement to invoke that label", but the problem with your code is that you forgot a ret statement in your Mult loop.
Also, your code terminated ungracefully once you were done with the Loop part of the code (you ran through the Mult loop code again before encountering the halt.)
The following code works (but note that it is not ideal -- among other things, it does not account for negative values and overflow):
.pos 0x200
.align 4
InputArray:
.long 5
.long 10
Done: .long 0x0
.pos 0x400
.align 4
OutputArray:
.pos 0x0
irmovl InputArray,%eax
irmovl OutputArray, %esi
Loop:
mrmovl (%eax), %ecx # get first element from InputArray
mrmovl (%eax), %edi # a copy of first element used for multiplication
irmovl $4, %ebx # increment the pointer of InputArray
addl %ebx, %eax
mrmovl (%eax), %edx # get second element from InputArray
irmovl $1, %ebx # add first element to its copy for the amount of second element
subl %ebx, %edx
jg mult
rmmovl %ecx,(%esi) # output value to OutputArray
jmp Exit
mult:
addl %edi, %ecx
subl %ebx, %edx
jg mult
ret
Exit: halt
User contributions licensed under CC BY-SA 3.0