0
votes

I'm learning assembly in Linux 32bit . the code bellow converts the uppercase string to lowercase .

I have this strange result, when I change the order of registers in mov instructions . for example if I swap the registers name in these instructions the output disappears .

mov ecx, msg         
mov edx, msglen

it doesn't work if changed to

mov edx, msg 
mov ecx, msglen 

so is it a must to have the registers in this order eax ebx ecx edx ... i'm confused (noob)
- this is the code that works

section .data

msg: db "UPPERCASE", 10  ;  string 
msglen: equ $-msg        ;  string length 

section .bss
section .text
global _start

_start:
    mov ebx, msg  
    mov eax, 9  ; number of iterations equ number of char in str

doloop: 
    add byte  [ebx], 32  ; label doloop
    inc ebx
    dec eax 
    jnz doloop

    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, msglen
    int 80h 
    mov eax, 1
    mov ebx, 0 
    int 80h 
1
It means that a function (int 80h) takes arguments in specific registers. In expects message pointer in ecx, message length in edx. You cannot shuffle function arguments!Andrey Nasonov
This sort of question is probably best answered by looking at the ABI of your platform.EOF

1 Answers

3
votes

Yes and no. Your example is rather poor in the fact that it swaps the meaning of registers (exchanging the values in ECX and EDX). The Linux kernel requires the inputs to be in registers EBX (the first parameter), ECX (the second), and EDX (the third). Therefore, if you exchange the values in ECX and EDX, you are actually changing the parameter order, telling the system call the wrong information, and you'll undoubtedly get a wrong result.

If, instead, you had simply swapped the order in which you moved data into the registers, nothing would have changed. You can move data into registers in whatever order you want.