4
.section .data

astring: .asciz "11010101"
format: .asciz "%d\n"

.section .text
.globl _start

_start:

xorl %ecx, %ecx

movb astring(%ecx,1), %al
movzbl %al, %eax

pushl %eax
pushl $format
call printf
addl $8, %esp


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

假设我想打破 .asciz 字符串 1101011 并得到它的第一个。我该怎么做?上面的代码不起作用,它打印 49 或其他东西。

4

2 回答 2

2

更改printffrom %dto的转换说明符%c以打印字符而不是其 ascii 值。

于 2008-12-30T02:17:33.827 回答
1

4年后。我正在学习用 GNU Assembler 在 asm 中编程。我这样做是为了练习:

.section .rodata
.LC0:
.string "This is the number: %d \n"
.data
.type str, @object
str:
.long .LC0

.section .text
.globl main
.type main, @function
.extern printf
main:
push %ebp
movl %esp, %ebp
andl $-16, %esp
subl $12, %esp
movl $2600, 4(%esp)
movl str, %edx
# Simple printf
movl %edx, %eax
movl %eax, (%esp)
call printf

# putchar
# for loop
movl $0, -4(%ebp)
jmp .check_for
.for_loop:
movl -4(%ebp), %eax
movl str, %edx
leal (%edx, %eax), %eax
movzbl (%eax), %eax
movsbl %al, %eax
movl %eax, (%esp)
call putchar
addl $1, -4(%ebp)
.check_for:
cmp $0x00, (%esp)
jnz .for_loop
leave
ret
于 2012-03-20T07:30:24.323 回答