andandandand
andandandand

Reputation: 22270

Splitting a string 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 wanna break the .asciz string 1101011 and get it's first one. How do I go about it? The code above ain't working, it prints 49 or something.

Upvotes: 4

Views: 1825

Answers (2)

charlyasap
charlyasap

Reputation: 11

4 years later. I'm learning to programming in asm with 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

Upvotes: 1

Robert Gamble
Robert Gamble

Reputation: 109062

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

Upvotes: 2

Related Questions