I am a beginner in assembly programming and want to clarify some of my doubts that aroused in interpreting this code
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro exit 0
mov rax,60
mov rdi,0
syscall
%endmacro
%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .data
a dw 123AH
section .bss
b resb 2;
buff resb 2;
section .code
global _start
_start:
accept b,2
mov rsi,a ;3
mov rbx,[rsi] ;6
call hextoascii
mov rsi,buff
exit
hextoascii:
mov rcx,4
mov rsi,buff
back:
rol bx,4
mov al,bl
and al,0Fh
cmp al,09H
jbe add30h
add al,7h
add30h:
add al,30h
mov [rsi],al
inc rsi ;4
loop back
print buff,2 ;7
ret
I have a few questions to ask :
- Is there any difference between the following two with respect to the their storage in memory or any other a) a resb 2 b) a resw 1
- If I accept a variable from user then I have to reserve another byte for the "Enter" key pressed. Is it so ? If yes, then will the ascii value of "Enter" be concatenated as the last byte of the variable ?
The instruction : mov rsi,a (a=1234H) To which memory location of 'a' does rsi points to ? ie- does it store the address of 4 or the address of 1.
If I increment rsi then will it point to next digit of the variable a ? How shall I interpret "inc rsi" in the 4th last line of the code ? By how much postion does rsi gets incremented assuming that it currently points to the base address of "a" ? And will the increment depend on the size of varaible that it points to ?
How is 'a' present in memory ? ie- Is 1 present at the lowest address or present at the highest address with respect to other digits?
In the instruction : mov rbx,[rsi] How much of 'a' goes into rbx and what is the maximum limit of 'a' that rbx can store inside it ?
- In the instruction : print buff,4 It is printing only half the value of 'a' (12) and not '1234' completely. I have read that the 2nd argument of print macro should be the size of the variable (here 'buff') but since the size of buff is 2 bytes, it is just printing the half and not completely. Rather if I replace 2 by 4, then complete '1234' gets printed. What does the size mean here ? Is it the no. of bytes or something else ?
inc rsiincrements the 64-bit integer value by 1. When used as a pointer, that means the next byte, always, regardless of anything else.print /x *(char*)$rsi(orx /xbc $rsi) to eXamine a byte in memory to see what RSI is pointing to. You can answer most of these questions yourself with a little experimentation.