【问题标题】:Splitting a string on AT&T IA-32 Linux Assembler (gas)在 AT&T IA-32 Linux Assembler (gas) 上拆分字符串
【发布时间】:2010-09-28 19:12:03
【问题描述】:
.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 或其他东西。

【问题讨论】:

  • 添加了 c 标签,因为问题实际上是关于 C 的 printf 函数。
  • 读心者,我无法读懂你的心思。你想要什么输出? 1 还是 1101011?
  • “并得到它的第一个”。所以第一个。 1.

标签: c linux assembly x86 gnu-assembler


【解决方案1】:

printf 的转换说明符从 %d 更改为 %c 以打印字符而不是其 ascii 值。

【讨论】:

  • 太好了,现在我想从我的 10i101010101 链中获得三人一组,我该怎么做?我尝试将 movb astring(%ecx,1), %al 的比例更改为 3 和 2,但没有成功。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    相关资源
    最近更新 更多