Reputation: 3
Tricky question about a a project in machine code, effectively Assembly code without labels. We are trying to find the length of a list that will change each time. The problem is, without labels, we can't change the PC offset dynamically to step back the correct amount in the memory to start iterating through the list. I'll provide the code below:
0011 0000 0000 0000 ; Starting memory location
0000 0000 0100 0011 ; List items, also below
0000 0000 0110 1110
0000 0000 0110 1011
0000 0000 0110 1101
0000 0000 0100 1111
0000 0000 0101 1110
0000 0000 0110 0011
0000 0000 0000 0000
1110011111110111 ; LEA R3, #-10
0101010010100000 ; AND R2, R2, #0
0110001011000000 ; LDR, R1, R3, #0
0000010000000110 ; BRz, #-7
0001001001000010 ; ADD R1, R1, R2
0001000001100000 ; ADD R0, R1, #0
1111000000100001 ; OUT
0001010010100001 ; ADD R2, R2, #1
0001011011100001 ; ADD R3, R3, #1
0000101111111000 ; BRnp #-8
1111000000100101 ; Halt
This code should take a list and:
For each data value:
This works, the problem is, on the line BRz #-7
we need the #-7
to change dynamically based on the size of the list initally loaded in. Any thoughts, ideas, or solutions are greatly appreciated!
Upvotes: 0
Views: 39