I literally looked around for an hour, still found nothing. I tried mov ah, byte [rdx]
but got a segfault. The reason I can't just enter the value directly into ah
and have to use rdx
is that rdx
is a parameter in a procedure I need to write. Is there perhaps an opposite of movzx
or something of the sort? I'm probably asking a really noobish question here, but I have literally looked everywhere and found nothing that helps.
Asked
Active
Viewed 779 times
0
Peter Cordes
- 328,167
- 45
- 605
- 847
mediocrevegetable1
- 4,086
- 1
- 11
- 33
-
1Consider mov ah, dl – Hans Passant Feb 02 '21 at 17:06
-
1If you want a byte other than the one in `dh` or `dl`, you have to use bit shifting instructions to extract the byte value. – ecm Feb 02 '21 at 17:07
-
@HansPassant if I use this procedure in a C program with dl as the third argument, will it know to use dl as the argument or will it try using rdx still? – mediocrevegetable1 Feb 02 '21 at 17:08
-
@ecm can you please explain how the bit-shifting would help me solve this problem? – mediocrevegetable1 Feb 02 '21 at 17:11
-
https://www.geeksforgeeks.org/integer-promotions-in-c/ – Hans Passant Feb 02 '21 at 17:12
-
2@mediocrevegetable1 With bit shifting, you can shift the desired byte to the least significant byte of a register and then copy it to another register. – fuz Feb 02 '21 at 17:14
-
@HansPassant I am aware of integer promotion, but how would that work with procedure parameters? – mediocrevegetable1 Feb 02 '21 at 17:18
-
@fuz I haven't heard of the least significant byte before, I'll just look it up and get back to you. If by least sig. byte you mean leftmost byte, I assume it already will be there, as I think when you do `mov rdx, 0xff` it puts `0xff` at the leftmost byte. – mediocrevegetable1 Feb 02 '21 at 17:19
-
@mediocrevegetable1 Yes, this is the least significant byte, i.e. the one with the least place value. You can then do `mov ah, dl` as Hans Passant already recommendend. – fuz Feb 02 '21 at 17:28
-
@fuz Ah, so `dl` will access the least significant byte of `rdx` automatically? interesting. – mediocrevegetable1 Feb 02 '21 at 17:31
-
[UPDATE] I tried out using `dl` and indeed, it works. Major thanks to everyone who helped. I also understand what @HansPassant meant when he showed integer promotion now. – mediocrevegetable1 Feb 02 '21 at 17:39
-
1@mediocrevegetable1 Yes, `dl` is the least significant byte of `rdx`. Please refer to the Intel Software Development Manuals on what registers an x86 processor has. – fuz Feb 02 '21 at 18:05
-
Will do, thanks for the advice. – mediocrevegetable1 Feb 02 '21 at 18:21