Defining integers in GAS 在gas中定义整数:前一节汇编示例中的整数是以立即数的形式存在的,在汇编中还可以使用.int ,.short 和.long的伪操作符来定义不同尺寸的有符号整数或者整数数组,...
# quadtest.s - An example of quad integers .section .data data1: .int 1, -1, 463345, -333252322, 0 data2: .quad 1, -1, 463345, -333252322, 0 .section .text .globl _start _start: nop movl $1, %eax movl $0, %ebx int $0x80 |
$ as -gstabs -o quadtest.o quadtest.s $ ld -o quadtest quadtest.o $ gdb -q quadtest Reading symbols from /home/zengl/Downloads/asm_example/quadtest...done. (gdb) break *_start Breakpoint 1 at 0x8048074: file quadtest.s, line 10. (gdb) r Starting program: /home/zengl/Downloads/asm_example/quadtest Breakpoint 1, _start () at quadtest.s:10 10 nop (gdb) x/5d &data1
0x8049084 <data1>: 1 -1 463345 -333252322
0x8049094 <data1+16>: 0
(gdb) x/5d &data2
0x8049098 <data2>: 1 0 -1 -1
0x80490a8 <data2+16>: 463345
|
(gdb) x/20bx &data1
0x8049084 <data1>: 0x01 0x00 0x00 0x00 0xff 0xff 0xff 0xff
0x804908c <data1+8>: 0xf1 0x11 0x07 0x00 0x1e 0xf9 0x22 0xec
0x8049094 <data1+16>: 0x00 0x00 0x00 0x00
(gdb) x/40bx &data2
0x8049098 <data2>: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x80490a0 <data2+8>: 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff
0x80490a8 <data2+16>: 0xf1 0x11 0x07 0x00 0x00 0x00 0x00 0x00
0x80490b0 <data2+24>: 0x1e 0xf9 0x22 0xec 0xff 0xff 0xff 0xff
0x80490b8 <data2+32>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
(gdb) x/5gd &data2
0x8049098 <data2>: 1 -1
0x80490a8 <data2+16>: 463345 -333252322
0x80490b8 <data2+32>: 0
(gdb) help xExamine memory: x/FMT ADDRESS. ADDRESS is an expression for the memory address to examine. FMT is a repeat count followed by a format letter and a size letter. Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal), t(binary), f(float), a(address), i(instruction), c(char) and s(string). Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes). The specified number of objects of the specified size are printed according to the format. |
movq source, destination |
# mmxtest.s - An example of using the MMX data types .section .data values1: .int 1, -1 values2: .byte 0x10, 0x05, 0xff, 0x32, 0x47, 0xe4, 0x00, 0x01 .section .text .globl _start _start: nop movq values1, %mm0 movq values2, %mm1 movl $1, %eax movl $0, %ebx int $0x80 |
$ as -gstabs -o mmxtest.o mmxtest.s $ ld -o mmxtest mmxtest.o $ gdb -q mmxtest Reading symbols from /home/zengl/Downloads/asm_example/mmxtest/mmxtest...done. (gdb) break *_start+1 Breakpoint 1 at 0x8048075: file mmxtest.s, line 11. (gdb) r Starting program: /home/zengl/Downloads/asm_example/mmxtest/mmxtest Breakpoint 1, _start () at mmxtest.s:11 11 movq values1, %mm0 (gdb) s 12 movq values2, %mm1 (gdb) s 13 movl $1, %eax (gdb) print $mm0 $1 = {uint64 = -4294967295, v2_int32 = {1, -1}, v4_int16 = {1, 0, -1, -1}, v8_int8 = {1, 0, 0, 0, -1, -1, -1, -1}} (gdb) print $mm1 $2 = {uint64 = 72308588487312656, v2_int32 = {855573776, 16835655}, v4_int16 = {1296, 13055, -7097, 256}, v8_int8 = {16, 5, -1, 50, 71, -28, 0,1}} (gdb) print/x $mm1 $3 = {uint64 = 0x100e44732ff0510, v2_int32 = {0x32ff0510, 0x100e447}, v4_int16 = {0x510, 0x32ff, 0xe447, 0x100}, v8_int8 = {0x10, 0x5, 0xff, 0x32, 0x47, 0xe4, 0x0, 0x1}} (gdb) print $st0 $4 = -nan(0xffffffff00000001) (gdb) print $st1 $5 = -nan(0x100e44732ff0510) |
movdqa source, destination |
# ssetest.s - An example of using 128-bit SSE registers .section .data values1: .int 1, -1, 0, 135246 values2: .quad 1, -1 .section .text .globl _start _start: nop movdqu values1, %xmm0 movdqu values2, %xmm1 movl $1, %eax movl $0, %ebx int $0x80 |
$ as -gstabs -o ssetest.o ssetest.s $ ld -o ssetest ssetest.o $ gdb -q ssetest Reading symbols from /home/zengl/Downloads/asm_example/ssetest/ssetest...done. (gdb) break *_start+1 Breakpoint 1 at 0x8048075: file ssetest.s, line 11. (gdb) r Starting program: /home/zengl/Downloads/asm_example/ssetest/ssetest Breakpoint 1, _start () at ssetest.s:11 11 movdqu values1, %xmm0 (gdb) s 12 movdqu values2, %xmm1 (gdb) s 13 movl $1, %eax (gdb) print $xmm0 $1 = {v4_float = {1.40129846e-45, -nan(0x7fffff), 0, 1.89520012e-40}, v2_double = {-nan(0xfffff00000001), 2.8699144274488922e-309}, v16_int8 = {1, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 78, 16, 2, 0}, v8_int16 = {1, 0, -1, -1, 0, 0, 4174, 2}, v4_int32 = {1, -1, 0, 135246}, v2_int64 = {-4294967295, 580877146914816}, uint128 = 0x0002104e00000000ffffffff00000001} (gdb) print $xmm1 $2 = {v4_float = {1.40129846e-45, 0, -nan(0x7fffff), -nan(0x7fffff)}, v2_double = {4.9406564584124654e-324, -nan(0xfffffffffffff)}, v16_int8 = {1,0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1}, v8_int16 = {1, 0, 0,0, -1, -1, -1, -1}, v4_int32 = {1, 0, -1, -1}, v2_int64 = {1, -1}, uint128 = 0xffffffffffffffff0000000000000001} (gdb) |
11 movdqa values1, %xmm0 (gdb) s Program received signal SIGSEGV, Segmentation fault. _start () at ssetest.s:11 11 movdqa values1, %xmm0 (gdb) s Program terminated with signal SIGSEGV, Segmentation fault. The program no longer exists. (gdb) |
fbld source |
# bcdtest.s - An example of using BCD integer values .section .data data1: .byte 0x34, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 data2: .int 2 .section .text .globl _start _start: nop fbld data1 fimul data2 fbstp data1 movl $1, %eax movl $0, %ebx int $0x80 |
$ as -gstabs -o bcdtest.o bcdtest.s $ ld -o bcdtest bcdtest.o $ gdb -q bcdtest Reading symbols from /home/zengl/Downloads/asm_example/bcdtest/bcdtest...done. (gdb) break *_start+1 Breakpoint 1 at 0x8048075: file bcdtest.s, line 11. (gdb) r Starting program: /home/zengl/Downloads/asm_example/bcdtest/bcdtest Breakpoint 1, _start () at bcdtest.s:11 11 fbld data1 (gdb) x/10bx &data1
0x8049094 <data1>: 0x34 0x12 0x00 0x00 0x00 0x00 0x00 0x00
0x804909c <data1+8>: 0x00 0x00
|
11 fbld data1 (gdb) s 12 fimul data2 (gdb) info all ................... //省略N行输出 st0 1234 (raw 0x40099a40000000000000) |
12 fimul data2 (gdb) s 13 fbstp data1 (gdb) info all ................... //省略N行输出 st0 2468 (raw 0x400a9a40000000000000) |
13 fbstp data1 (gdb) s 14 movl $1, %eax (gdb) x/10bx &data1
0x8049094 <data1>: 0x68 0x24 0x00 0x00 0x00 0x00 0x00 0x00
0x804909c <data1+8>: 0x00 0x00
|