flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Strange behaviour when using structures.

Thread Post new topic Reply to topic

Joined: 28 Aug 2017
Posts: 17
Hi. I wonder what is wrong with this code:
; This is an Educational Program

format PE console
use32   ; x86_32
entry start 

include 'win32a.inc'

struct PNT 
        x dd ? 
        y dd ?
        z dd ?
        q dd ? 
; This is the data section:
; =======================================================
section '.data' data readable writeable 
        my_PNT          PNT  2,3,4,5
        ;mem            dd 1 dup(0)

; =======================================================
section '.text' code readable executable 

        ; Your program begins here
        mov eax, [my_PNT] ; Output -> 2
        mov eax, [my_PNT + 1] ; Output -> 3000000
        mov eax, [my_PNT + 2] ; Output -> 30000
        mov eax, [my_PNT + 3] ; Output -> 300
        mov eax, [my_PNT + 4] ; Output -> 3
        ;call print_eax ; Printing the number in hexa format in the console. This comes from the fine training.inc

        ; Exit the process: 
        push 0
        call [ExitProcess]

include 'C:\Users\MrNoLife\Desktop\ASM resources\x86-asm-foundations\#asm_prog_ex-master\include\training.inc'

Look at the code that begins after the start label. In the first line I move the thing number that is in address my_PNT in eax (the number is my_PNT.x which is 2) now after that I move from the base address of my_PNT to the next byte I get this strange result "3000000". Why is this happening ? Can someone explain me ?
Post 13 Sep 2017, 11:31
View user's profile Send private message Reply with quote
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 15912
Location: SDSS J140821.67+025733.2
Your values are defined as dd so they take four bytes each. You will need to adjust the offsets:
        mov eax, [my_PNT + 4*0] ;first value
        mov eax, [my_PNT + 4*1] ;second value
        mov eax, [my_PNT + 4*2] ;third value
        mov eax, [my_PNT + 4*3] ;fourth value
        mov eax, [my_PNT + 4*4] ;fifth value    
But actually since you use a structure you can access the value by the symbol name:
        mov eax, [my_PNT.x]
        mov eax, [my_PNT.y]
        mov eax, [my_PNT.z]
        mov eax, [my_PNT.q]    
Post 13 Sep 2017, 11:48
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.