提问人:Jer 提问时间:3/10/2023 更新时间:3/10/2023 访问量:45
用于调用函数的汇编语言嵌套循环 问题描述
Assembly Language Nested Loop to call Functions Issue
问:
我调用函数像素的循环不起作用。它调用该函数一次并停止循环。这是我的代码:
.syntax 统一
.cpu 皮质-m4
.equ DISPLAY, 0xD0000000 //内存:像素范围
.text
.global pixel
.thumb_func
.align
// Draws the pixel word passed in R2 to the pixel location given by the column in R0 and the row in R1
pixel:
//r0 = col (10-19) (input) //#0xD0000000
//r1 = row 75 (input) //i
//r2 = color_red (input)
//r3 = #240
mov r3, #240
mul r1, r3 //row * 240
add r1, r0 //i = (row * 240) + col
ldr r0, =DISPLAY //load the memmory address of #0xD0000000 into r0
str r2, [r0, r1, lsl #2] //store value in r2 (color red) into memory address specified by r0 + r1 * 4
//dont need to loop and increment memory adress (index) i because the function only suppose to print 1 pixel at a time
bx lr //print 1 [color] pixel at i
.global rect
.thumb_func
.align
// Fills in a rectangle with the pixel word passed in R0.
// The rectangle fills all pixels between (column,row) coordinates of (50,150) to (149,249), inclusive.
rect:
mov r3, r0
//r0 = color_? j
//r1 = i i
//r2 = j color_?
//r3 =
//r12 =
mov r1, #150 //r1 = i (row)
loopi:
mov r2, #50 //r2 = j (col)
loopj:
// Body of nested loop is here
push {r4-r11, lr} // preserve registers
mov r4, r1 //move col into r4
mov r5, r2 //move row into r5
mov r6, r3 //move color into r6
mov r2, r6 // r2 = color
mov r0, r5 // r0 = col
mov r1, r4 // r1 = row
bl pixel // call pixel function
mov r2, r0
pop {r4-r11, pc} // restore registers and return
add r2, #1 // increment col
cmp r2, #150
blo loopj
add r1, #1 // increment row
cmp r1, #250
blo loopi
bx lr
.end
我尝试了不同的寄存器或在循环之外的其他地方调用推送流行音乐。然而,无论我做什么,循环都根本不起作用。
答:
-1赞
Jer
3/10/2023
#1
.syntax unified
.cpu cortex-m4
.equ DISPLAY, 0xD0000000 //memory: range of pixels
.text
.global pixel
.thumb_func
.align
// Draws the pixel word passed in R2 to the pixel location given by the column in R0 and the row in R1
pixel:
//r0 = col (10-19) (input) //#0xD0000000
//r1 = row 75 (input) //i
//r2 = color_red (input)
//r3 = #240
mov r3, #240
mul r1, r3 //row * 240
add r1, r0 //i = (row * 240) + col
ldr r0, =DISPLAY //load the memmory address of #0xD0000000 into r0
str r2, [r0, r1, lsl #2] //store value in r2 (color red) into memory address specified by r0 + r1 * 4
//dont need to loop and increment memory adress (index) i because the function only suppose to print 1 pixel at a time
bx lr //print 1 [color] pixel at i
.global rect
.thumb_func
.align
// Fills in a rectangle with the pixel word passed in R0.
// The rectangle fills all pixels between (column,row) coordinates of (50,150) to (149,249), inclusive.
rect:
//r0 = color_? j
//r1 = i i
//r2 = j color_?
//r3 =
//r12 =
push {r4-r11, lr} // preserve registers
mov r6, r0
mov r4, #150 //r4 = i (row)
loopi:
mov r5, #50 //r5 = j (col)
loopj:
// Body of nested loop is here
mov r2, r6 // r2 = color
mov r0, r5 // r0 = col
mov r1, r4 // r1 = row
bl pixel // call pixel function
add r5, #1 // increment col
cmp r5, #150
blo loopj
add r4, #1 // increment row
cmp r4, #250
blo loopi
pop {r4-r11, pc} // restore registers and return
.end
评论
0赞
Jer
3/10/2023
只需在嵌套的 do-while 循环之外推并弹出即可。使用扩展寄存器 R4 和 R5 作为环路增量的索引,而不是使用 R1 和 R2。比前面的代码更简单,更直观。
1赞
Peter Cordes
3/10/2023
解释代码中不同之处的文本应该是答案本身的一部分(在代码块之外),而不是注释。(您可以编辑,因为您一开始就没有这样做。
评论