Hello assemblers :) .
I am trying to sort a word backwards, like this: abcde -> edcba
This is my code

section .bss
	aloc resb 10

   %macro print 2 
      mov   eax, 4
      mov   ebx, 1
      mov   ecx, %1
      mov   edx, %2
      int   80h
   %endmacro

section .data
	str:	db	'abcde',10
	strlen:	equ	$-str

section .text
global _start
_start:
	mov ax, strlen/2
	mov si,0
.loop:
	mov dx , [str + si]
	mov cx , [str + strlen - si] ; error 31
	mov [aloc + si], dx
	mov [aloc + strlen - si], cx; error 33
        inc si
	print aloc, strlen

	test ax,si
	jnz .loop
	
;***EXIT***
	mov eax, 1            ; (sys_exit)
	mov ebx, 0            ; Exit with return code of 0 (no error)
	int 80h

Errors

lab4a.asm:31: error: invalid effective address
lab4a.asm:33: error: invalid effective address

Would someone help me, pls?

Try using di instead of trying to do all that crazy addition followed by subtraction.

mov si,0
mov di, strlen
.loop:
	mov dx , [str + si]
	mov cx , [str + di] 
	mov [aloc + si], dx
	mov [aloc + di], cx
        inc si
        dec di

Thank you. But this is what i get

ld lab4a.o -o lab4a
lab4a.o: In function `_start':
lab4a.asm:(.text+0x2): relocation truncated to fit: R_386_16 against `.data'
lab4a.o: In function `_start.loop':
lab4a.asm:(.text+0xc): relocation truncated to fit: R_386_16 against `.data'
lab4a.asm:(.text+0x12): relocation truncated to fit: R_386_16 against `.data'
lab4a.asm:(.text+0x18): relocation truncated to fit: R_386_16 against `.bss'
lab4a.asm:(.text+0x1e): relocation truncated to fit: R_386_16 against `.bss'

Hm, i've changed everything to extended and had no problems at linking, but something else had to get in the way...

strace ./lab4a
execve("./lab4a", ["./lab4a"], [/* 37 vars */]) = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++

Sorry, no . I did try though. I can't understand how it works.
Maybe you want to try and see what's the problem? Please?
I would really appreciate faster help, and it's not because i want to hurry someone, it's just the problem with time. I have to solve this fast so i can move on to other laboratory work(I'm a student).
Thanks!

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