ARM アセンブリで 2 つのサブルーチンを作成しています。ベクトルの最初の利用可能な位置にバイト値を格納することになっています。私のコードでは「appendbyte」と呼ばれるこれは、うまく機能しているようです。もう 1 つは、このベクターに格納されている値を出力することになっていますが、その中のすべての要素に対して 0 を出力しますが、これは正しくありません。
ベクター構造体には、ベクターの最初のアドレスに要素数が格納されており、最大 255 個の値を格納する必要があります。
完全なコードは次のとおりです。
.text
.global main
.equ num, 255 @ Max number of elements
main:
push {lr}
mov r8, #7
bl appendbyte
mov r8, #5
bl appendbyte
mov r8, #8
bl appendbyte
bl printvector
pop {pc}
printvector:
push {lr}
ldr r4, =vet @ stores the address of the start of the vector in r4
ldr r5, [r4], #1 @ stores the number of elements in r5
loop:
cmp r5, #0 @if there isn't elements to print
beq fimimprime @quit subroutine
ldr r0, =node @r0 receives the print format
ldr r1, [r4], #1 @stores in r1 the value of the element pointed by r4. Increments r4 after that.
sub r5, r5, #1 @decrements r5 (number of elements left to print)
bl printf @call printf
b loop @continue on the loop
endprint:
pop {pc}
appendbyte:
push {lr}
ldr r4, =vet @stores in r4 the beggining address of the vector
ldr r5, [r4], #1 @stores in r5 the number of elements and makes r4 point to the next address
add r6, r4, r5 @stores in r6 the address of the first available position
str r8, [r6] @put the value at the first available position
ldr r4, =vet @stores in r4 the beggining address of the vector
add r5, r5, #1 @ increment the number of elements in the vector
str r5, [r4] @ stores it in the vector
pop {pc}
.data @ Read/write data follows
.align @ Make sure data is aligned on 32-bit boundaries
vet: .byte 0
.skip num @ Reserve num bytes
.align
node: .asciz "[%d]\n"
.end
問題が明確だったことを願っています。前もって感謝します!