Creating a substring in assembler IA-32 (gas)
I want to create a substring (ministring) of 3 asciz characters from my original (thestring). It's not about printing at startup, so I don't know what the hell I'm doing. Why doesn't he print? Am I creating the constellation correctly?
.section .data
thestring: .asciz "111010101"
ministring: .asciz ""
formatd: .asciz "%d"
formats: .asciz "%s"
formatc: .asciz "%c"
.section .text
.globl _start
_start:
xorl %ecx, %ecx
ciclo:movb thestring(%ecx,1), %al
movzbl %al, %eax
movl %eax, ministring(%ecx,1)
incl %ecx
cmpl $3, %ecx
jl ciclo
movl thestring, %eax
pushl %eax
pushl $formats
call printf
addl $4, %esp
movl $1, %eax
movl $0, %ebx
int $0x80
+1
source to share
1 answer
You haven't reserved enough storage space that the null-named ministring you create ... so when you write to that memory, you overwrite the value of formatd and formats (and therefore eventually something other than "% s" for printf).
Instead of locating the memory location, try the following:
ministring: .asciz " "
Also, instead of this:
movl %eax, ministring(%ecx,1)
I don't understand why you don't use this instead:
movb %al, ministring(%ecx,1)
Also, if you want to print ministring, instead:
movl thestring, %eax
Do it:
movl ministring, %eax
Also instead of this:
addl $4, %esp
Why not this:
addl $8, %esp
Also I suggest you use a debugger for:
- Pass the code
- Keep track of values ββheld in registers and in memory as you go through
- Know the location of any segmentation fault
+1
source to share