assembly 汇编语言嵌套循环调用函数问题

jq6vz3qz  于 2023-03-12  发布在  其他
关注(0)|答案(1)|浏览(124)

我调用一个函数pixel的循环不起作用。它调用了函数一次就停止循环。下面是我的代码:
.语法统一.cpu cortex-m4 .equ显示器,0xD 0000000//存储器:像素范围

.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

我尝试了不同的寄存器或在循环外调用push pop else,但无论我做什么,循环都不起作用。

pgvzfuti

pgvzfuti1#

.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

相关问题