Scanf ARM Assembly

前端 未结 2 1236
猫巷女王i
猫巷女王i 2021-01-17 05:24

I know there\'s a question here but I really don\'t understand what the OP did. I\'ve used x86 assembly before and for that you\'d do something like this:

p         


        
相关标签:
2条回答
  • 2021-01-17 05:37

    This is what ended up working for me:

    sub     sp, sp, #4
    
    @ Call scanf and store value in r4
    ldr     r0, addrInp
    mov     r1, sp
    bl      scanf
    ldr     r4, [sp]
    
    add     sp, sp, #4
    

    The value the user inputs ends up in r4 in this case. I don't understand why Jesters way didn't work but it just gave a segfault every time.

    0 讨论(0)
  • 2021-01-17 05:53

    ldr should by all means work. This certainly compiles:

    ldr r0, =fmtInput
    ldr r1, =num
    bl scanf
    
    .data
    num: .word 0
    fmtInput: .string "%d"
    
    0 讨论(0)
提交回复
热议问题