# 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,这是正确的。