Line break on AT & T IA-32 Linux Assembler (gas)

.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 

Suppose I want to break the string .asciz 1101011 and get it first. How can I do it? The code above does not work, it prints 49 or something like that.

+4
source share
2 answers

Change the printf conversion specifier from %d to %c to print the character instead of its ascii value.

+2
source

4 years later. I am learning asm programming using the GNU Assembler. I did it as a practice:

 .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 
+1
source

All Articles