1

why does an int 0x80 change value of rsi register as integer but not as char?

My code, it should read line and it does, if I want to print the whole line than there is no problem:

lp:
save
mov rax, 3
mov rbx, 2
mov rcx, rsi
mov rdx, 1 
int 80h
load

cmp [rsi], byte 0xa
je done
inc rsi
jmp lp
done:

save and load are macros which push and pop rax, rbx, rcx and rdx.

First iteration is everything ok, but second one the integer value of [rsi] changes but cahr value still the same as seen in gdb:

13: $rdi = 4206592
14: $rsi = 4206593
15: *(int*)($rdi) = 14391
16: *(int*)($rdi+1) = 56
17: *(char*)($rdi) = 55 '7'
18: *(char*)($rdi+1) = 56 '8'

In gdb I am looking at rdi because it should be the same values as rsi.

I tried to create static variable of size db and fill that variable instead of rsi. But I am learning how to allocate memory so this is not the purpose why I am doing that.

  • 2
    You may need to read this first: https://stackoverflow.com/questions/46087730/what-happens-if-you-use-the-32-bit-int-0x80-linux-abi-in-64-bit-code – Ruud Helderman Dec 28 '22 at 14:47
  • Are you reading from `stderr`? Are you using a 32-bit syscalls interface with 64-bit code? What that GDB output is supposed to mean? It shows that at `[rdi]` you have '7' and then '8'. – Margaret Bloom Dec 28 '22 at 14:51
  • @MargaretBloom the ouput shows '7' and '8' if it is casted as char but for the '7' (line 17) case the value is 14391 if casted as integer (line 15) and I do not know why... – Jakub Anderle Dec 28 '22 at 15:08
  • 2
    Do not use `int $0x80` in 64 bit programs. That's the entry point for 32 bit system calls which are only able to work with 32 bit arguments including 32 bit addresses. – fuz Dec 28 '22 at 15:46
  • @fuz That's not the cause of the confusion here so it's not a duplicate. – Timothy Baldwin Jan 01 '23 at 03:50

0 Answers0