Hey guys, I am new to assembly and I am having a problem compling the code.

section .text
global _start

_start:

xor eax,eax
push eax
push dword 0x71242776
push dword 0x76747977
push esp
pop esi
mov edi,esi
mov edx,edi
cld
mov ecx,0x80
mov ebx,0x41
xor eax,eax
push eax
lodsb
xor eax,eax
stosb
loop 0xb7
push esp
pop esi
mov eax,4            
mov ebx, 1            
int 80h            

_exit:
mov eax,1
mov ebx,0
int 80h

It errors out after it tries to compile

yo.asm:22: error: short relative jump outside segment
yo.asm:22: error: short jump is out of range

Not sure what the problem is. I think its the loop but for some reason when I take it out it compiles but does not display the varible.

Thanks for the help

You will never compile it! You Assemble and Link.

Your stack is a MESS! Your pushes are not paired with pops. For every push you should have a pop or adjust esp manually.

where is this address > 0xb7? Why use a hardcoded address? use a label.

It won't print anything really. for the sys_write system call, ecx is a pointer to the string to write to the terminal NOT a character.

What does it do anyways?

Sorry for the compile, yes, assemble and link!!! I am new to assembly, so I apologize for my ignorance. It looks as if the gas version I was using has/had a bug in it, atleast this is what I can tell from googling. So I updated and it assembled fine.
I thought maybe it was better since I am learning with ATT syntax

.data
x:
    .long   0
s:
    .string "%d\n\0"

.text
.global main
main:               

loop:   
push $0x23742573
push $0x71757572
push $0x76272520
push $0x73797973
push $0x72702471
push $0x24712072
push $0x22232377
push $0x20257174
push $0x71767323
push $0x24777575
push $0x73232371
push $0x73792472
push $0x23742077
push $0x71732423
push $0x78757876
push $0x25762479
push $0x22762473
push $0x70752222
push $0x78202570
push $0x76782373
push $0x75742072
push $0x25277073
push $0x23737378
push $0x74257476
push $0x79757222
push $0x75717822
push $0x78767471
push $0x27767778
push %esp 
pop %esi 
mov %esi,%edi 
mov %edi,%edx 
cld 
mov $0x80,%ecx 
mov $0x41,%ebx 
xor %eax,%eax 
push %eax 
lods %ds:(%esi),%al 
xor %ebx,%eax 
stos %al,%es:(%edi) 
loop 0x0
push %esp 
pop %esi 
mov $4,%eax            
mov $1,%ebx           
int $0x80             

break:

    xor %eax, %eax  
    ret


exit:
mov $1,%eax
mov $0,%ebx
int $0x80

when I go to link it, It gives me the error

(.text+0xa5): relocation truncated to fit: R_386_PC8 against `UND'

It looks like it doesnt like the loop 0xb7, so I changed it. Which is what you pointed out. However, when I remove it, or use a label, it (as you pointed out) does not print anything. I am trying to push a 128 bit string on the stack, decrypt and then display it in terminal.

Now it looks as if, ld/gcc is not liking what I am doing either.

Edited 4 Years Ago by peterbob

This article has been dead for over six months. Start a new discussion instead.