简体   繁体   中英

Initializing Negative Data Types in ARM Assembly

I am currently struggling on how to set a negative/signed data type in ARM assembly via raspberry pi. I do not mean loading and storing signed integers but rather how declare a signed half word in '.data.' Once compiled I get this message:

Error: unknown pseudo-op: '.shalfword'
file: third.s
.section .data
a:.shalfword -2

Using the gnu assembler, the following should work.

    .text
    start:
        adr   r3,target   ; target address to r3
        ldrsh r0,[r3],#2  ; ldrsh will sign extend
        ldrsh r1,[r3]     ; .. and post increment to get the next.
        add   r0,r0,r1    ; r0 = -2 + -3
        bx    lr
    target:
       .short -2, -3

Here is a godbolt example of compiler output . An important point is that ARM doesn't deal with 8 or 16 bits in registers (like ah, al or ax in x86) and always uses 32 bit constants. So immediate loads of small negative constants will be like mvn rX,Y .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM