News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

high-order and low-order byte

Started by Telefunken, July 22, 2006, 12:02:57 AM

Previous topic - Next topic

hutch--

Dasar,

You cannot access the content of ESP EBP ESI or EDI in that manner as it is built into the hardware this way. You can access these 4 registers as a WORD value as they have a corresponding SP BP SI and DI that are 16 bit but there are no BYTE sized versions of these registers.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Dasar

Quote from: hutch-- on July 23, 2006, 07:28:02 AM
Dasar,

You cannot access the content of ESP EBP ESI or EDI in that manner as it is built into the hardware this way. You can access these 4 registers as a WORD value as they have a corresponding SP BP SI and DI that are 16 bit but there are no BYTE sized versions of these registers.

thank you hutch..

but as i understood from what you said:

i can access these registers only as WORD value, so why they do "Extended" ? i mean why they didn't let it SP, BP, SI, DI, why they make them extended registers while we can't access them as DWORD value ???

or, do you mean that the smallest value i can access in these registers is WORD value ?


maybe i misunderstood...

Synfire

You misunderstood. He meant the smallest value you can access them as is a word value. The extended versions are dwords.


dsouza123

The registers EAX, EBX, ECX, EDX have four methods of full or partial access, example EAX, AX, AH, AL for 32, 16 low, 8, 8 lowest bits
The registers ESP, EBP, ESI, EDI have two methods full dword and low 16 bit/word, example ESI, SI.

There are different ways of getting at the parts of a register, some not directly accessable, without losing register contents.


.data
get8  db 0
get16 dw 0
get32 dd 0

.code
xchg eax, esi  ; exchange eax and esi
mov get8, al   ; get lowest byte
mov get8, ah  ; get next to lowest byte
mov get16, ax  ; get low word
xchg eax, esi  ; re exchange eax and esi

xchg eax, esi
bswap eax    ; swap byte order from 0, 1, 2, 3 to 3, 2, 1, 0   low to high (little endian) Intel to high to low (big endian)
mov get8, al  ; get formerly highest byte
mov get8, ah ; get formerly next to highest byte
mov get16, ax  ; get formerly high word with bytes swapped
mov get32, eax  ; get dword in reverse byte order
bswap eax    ; swap back to original order
xchg eax, esi

bswap esi
mov get32, esi  ; less involved way to get esi in reverse byte order
bswap esi

; for ror and rol the carry and overflow flags will be overwritten
ror esi, 16
mov get16, si  ; get high word
rol esi, 16

ror esi, 8
mov get16, si  ; get word made of bytes 1 and 2   from bytes 0, 1, 2, 3 from low to high
rol esi, 8

mov get16, si  ; get low word

; to get a single bit from a 32 bit register various flags overwritten
bt esi, 7  ; high bit of low byte copied to carry flag
setc get8 ; carry flag stored in bit 0 of byte, the full value of the byte is 0 or 1, if CF zero then byte gets 0, else not zero byte gets 1

test esi, 128 ; AND with value of only high bit of low byte set
setnz get8 ; reverse of zero flag value put in bit 0 of byte, the value of the byte is 0 or 1  if zero gets 0, not zero gets 1

add esi, 0 ; sign flag gets value of bit 31
sets get8 ; sign flag put in bit 0 of byte, value 0 or 1


There are other ways that may involve temporary storage in memory or the stack, there are also destructive methods.

TNick

edi, esi, eip, esp can be accesed at word level, using di, si, ip, sp; anyway, don't mess with eip and esp yet. if you want to work at byte level, yes, you can transfer edi\esi to eax\ebx\ecx... or di\si to ax\bx\cx... work with it and put it back. or you can put your value in memory, work with it and then, when it's final, put it in your edi\esi. Don't forget that you should preserve ebx, edi and esi values, so "uses ebx edi esi" would be a good ideea.

Dasar

thank you for every one give me any info about my question ^_^