News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

moving a word to an array of bytes

Started by nickc86, May 09, 2017, 12:50:54 PM

Previous topic - Next topic

aw27

Quote from: jj2007 on May 09, 2017, 10:49:31 PM
If you return from the main thread, does the process exit?
If there is more than 1 thread it will not.

mineiro

hello sir nickc86;
yes, you're thinking right, you can access members of that array by the way you show.
But you can create a structure too, so you dont need calculate position member based on address because assembler can do that job to you. This is good because on a future you can insert or also change members place without need to go to code and change all member array reference by calculating.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

nickc86

This is for a project at university. I'll be copying this array using movsb, so I don't know that creating a structure for this is the way to go. This array will be going in to another block of memory for later processing. I will have something that looks like this


packetsize equ 8
numpackets equ 20
packet byte packetsize dup (?)
queue byte numpackets*packetsize dup (?)

And I'll want to do things like

mov eax, OFFSET queue
;get the third byte of the second packet
add eax, packetsize
mov bl, byte ptr [eax + 2]


Or doing this

;copy the 3rd packet
mov eax, 3
imul eax, packetsize
mov esi, OFFSET queue
add esi, eax
mov ecx, packetsize
mov edi, OFFSET packet
cld
rep movsb


Would I be going about this in the correct manner?

mineiro

yes, you can go that way.

QuoteBut I want to access those 8 bytes in the following order:
byte byte byte alignbyte word word


my_structure struct
bone db ?
btwo db ?
bthree db ?
pad db ?
wone dw ?
wtwo dw ?
my_structure ends

.data
;...
.code
  mov eax, OFFSET queue
  assume eax:ptr my_structure
  mov [eax].wone,5645
  mov cx,[eax].wone
  assume eax:nothing
  add eax, sizeof my_structure

  assume eax:ptr my_struct_inside_struct
  ...


--edited--
showing other examples:
  add eax,sizeof my_structure*packetsize+numpackets
  add eax, sizeof my_structure*sizeof other_struct*packetsize/sizeof otherstruct
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

mineiro

hello sir jj2007;

Quote from: jj2007 on May 09, 2017, 10:49:31 PM
Quote from: mineiro on May 09, 2017, 10:22:27 PM
On ms-dos an exitprocess can be just 'ret'. On windows too

On Windows, ret will trigger RtlExitUserThread - not the best option. But it will indeed work most of the time.

See also Raymond Chen's If you return from the main thread, does the process exit?

Quote from: mineiro on May 09, 2017, 10:22:27 PM
On ms-dos an exitprocess can be just 'ret'. On windows too, but on linux not, but this is a bad pratice.

int 20h to .com, int 21h to .exe, int 80h on linux 32, syscall on linux 64, ExitProcess on windows 32 and 64...

I'd rather be this ambulant metamorphosis than to have that old opinion about everything

nidud

#20
deleted

RuiLoureiro