Academy - Intro to Assembly - Data Movement Question

Hello guys.

im stuck in this exercise. THe next code was provided by HTB:

global _start

section .text
_start:
mov rax, 1024
mov rbx, 2048
xchg rax, rbx
push rbx

i need to solve the next question:

Add an instruction at the end of the attached code to move the value in “rsp” to “rax”. What is the hex value of “rax” at the end of program execution?

note: i dont understand what to do next. Asambly topics have been a nightmare to me to understand and solve.
This is the result. and it s wrong. i dont know why.

gef➤ r

Starting program: /home/kali/Desktop/mov2.o

zsh:1: exec format error: /home/kali/Desktop/mov2.o

During startup program exited with code 126.

gef➤ disas _start

Dump of assembler code for function _start:

0x0000000000000000 <+0>: mov eax,0x400

0x0000000000000005 <+5>: mov ebx,0x800

0x000000000000000a <+10>: xchg rbx,rax

0x000000000000000c <+12>: push rbx

0x000000000000000d <+13>: mov rax,rsp

End of assembler dump.

gef➤

Please Help.

The problem occurs because the xchg command does not work with 64-bit registers unless they are prefixed with r. In this case, you need to use xchg rax, rsp, not xchg rbx, rax. The value of rsp will then be moved to rax and you will be able to find its hexadecimal value at the end of the program.

that code came from HTB. i already solve. i add this code at end "move rax, [rsp]

1 Like

kk