flat assembler
Message board for the users of flat assembler.

Index > Main > Help with memory management

Author
Thread Post new topic Reply to topic
Tovarisch



Joined: 06 Aug 2010
Posts: 3
Tovarisch
Hi!

I'm starting to program in ASM, and I have still a very poor level. I come from C++ in which memory operations are done by the compiler, I know a few things about segments and registers, but i want to have a better idea of how a computer's memory works, and how to manipulate it in ASM.
I ask for an explanation, thanks.
Post 24 Aug 2010, 12:26
View user's profile Send private message Reply with quote
guignol



Joined: 06 Dec 2008
Posts: 717
guignol
what segments, camarada? Razz
Post 24 Aug 2010, 13:02
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello,
Is not simple and not easily explained with a few examples, we say that if you want to program in asm in flat mode you need to know how your computer and the processor if you intend to program for the windows operating system is not much to learn about memory management.
The first thing to do is choose between programming 16bit, 32bit, 64bit, then study the instructions of the processor and the addressing methods used by the processor...
Some Example:

16bit:
Code:
       mov     ax,0xb800               ; Load in ax Address of VGA video memory for text mode 80*25
        mov     es,ax                   ; Copy in es ax
     xor     di,di                   ; Register di = 0

; now the two register es:di are used like a pointer

       mov     bl,'T'                        ; Load char 'T' in register bl
    mov     [es:di],bl          ; this put the char 'T' in video memory 
                                  ; es = 0xb800  di = 0
                                       ; the processor in 16bit mode compute the address in this way
                                       ; 0xb800 * 0x10 + 0x0
                                       ; we have wrote the 'T'char at phisical address 0xb8000    


32bit:
Code:
  mov     esi,offset x                    ; load in esi register address of variable x
        mov     eax,[esi]                       ; load in eax register variable x    


I think there are many tutorials on the internet about the first steps with assembly programming,otherwise you can start directly with the manuals that explain the operation of Intel processors or start from the classic 'Hello World' in asm

_________________
Nil Volentibus Arduum Razz
Post 24 Aug 2010, 13:56
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
> mov esi, offset x ; load in esi register address of variable x

Does this compile ???

> I know a few things about segments and registers

Segments are needed for real mode. In PM they still exist but work differently and you usually won't touch them from an application.
Post 26 Aug 2010, 22:54
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
> Does this compile ???
IN MASM yeah,
in FASM no but if you add this in EQU section:
Code:

offset EQU 
mov si,offset x
    

MASM = Intel sintax,it is bad ok but this is more clear that
Code:
mov si,x    
Razz

_________________
Nil Volentibus Arduum Razz
Post 27 Aug 2010, 10:21
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
mov si,x ; mov si, offset x
mov si,[x] ; mov si,memory x
mov si,[si+x] ; mov si,memory (pointer + offset) x
Post 27 Aug 2010, 11:10
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.