Intel汇编-扩展带符号整数

# An example of the MOVSX instruction (扩展带符号整数)


    .section .data
output:
    .asciz "The value is:%d\n"

    .section .text
    .globl main
main:
    nop
    movw $-79, %cx
    movl $0, %ebx
    movw %cx, %bx        # ebx   0xffb1   65457
    movsx %cx, %eax
    push %eax
    push $output
    call printf        # -79
    add $8, %esp

    call L2
    jmp L2

    movl $1, %eax
    movl $0, %ebx
    int $0x80

L2:
    nop
    movw $79, %cx
    xor %ebx, %ebx
    movw %cx, %bx
    movsx %cx, %eax
    push %eax
    push $output
    call printf        # -79
    add $8, %esp

# gcc -o 03-movsx 03-movsx.s -m32

# 扩展带符号和扩展无符号整数是不同的。
# 使用零填充高位会改变负数的数据值。
# 如,把值(-1)(1111 1111) 传送给双字会生成值 0000 0000 1111 1111,在带符号整数表示法中它是+127,而不是-1。
# 为了使带符号扩展能够起作用,新添加的位必须被设置为1。
# 因此,新的双字将生成值 1111 1111 1111 1111,这是带符号整数表示法的值-1,这是正确的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值