flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Relating to the High Level Programmer

Author
Thread Post new topic Reply to topic
iceman90289



Joined: 06 Oct 2008
Posts: 5
Location: California
iceman90289 06 Oct 2008, 01:57
I have been programming with C#, BASIC, C, CPP, PHP and HTML for a while... i never saw anything quite like assembly.. its complex nature has grabbed my intrest. I have been looking at code and registers for about a day now and im not feeling that i made any progress learning this very capable language. If someone would like to IM me, or better yet, make this thread serve as some type of walkthrough for Assembly Code that is explained in a way a C# programmer would understand, i'd appreciate that. Im sure other people in my situation would to. Basically my problem is that nothing makes sense here. i understand im working with the processor, and im getting an idea of how low of a level Assembly actually is... but thats not enough. I want to understand the syntax. Thanks in advance Smile
Post 06 Oct 2008, 01:57
View user's profile Send private message AIM Address MSN Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1898
DOS386 06 Oct 2008, 06:18
Look at some Hello world programs and other examples and try to enhance them. Try some math:

Code:
; void main(void) ; NOT needed Laughing
; #include ..... ; NOT needed Laughing
; int i ; INT is an instruction in ASM, not "integer of unpredictable type and size" Laughing 
; if (i=0) ; There is no IF instruction in ASM ... oops (i==0) Laughing
mov EAX,$FFFFFFFF
inc EAX    ; Now 0
inc EAX    ; Now 1
shl EAX,4  ; Now 16 = $0000'0010
ud2        ; Crash ... check that EAX indeed is 16 Laughing
    
Post 06 Oct 2008, 06:18
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Oct 2008, 09:44
iceman: I suggest starting with 32bit windows assembly, it is somewhat easier to grasp at the beginning than 16bit real mode (DOS) assembly.

I think looking into how instructions are encoded would explain a lot to you. For example why you can use certain combination of parameters, but not others, etc.

In C#, you can do anything that makes sense syntax-wise, and compiler will translate it into series of step with desired results. But in assembly, you are not limited by "artificial" syntax. In assembly, every statement must correspond 1:1 to one CPU instruction, so you are limited by the processor architecture, not by the language.

Because of that, you cannot do certain things which would make sense syntactically, like move from memory to memory directly ("mov [var1], [var2]").

Another new concept might be memory, which in assemby beheaves strictly like array of bytes. Closest to this was probably C, not sure how much you spent with it. This array is indexed by number called "offset" or simply "pointer". But, in assembly, this pointer is not anything special, like in C. It is just plain number like every else, and it's only on you whether you use the number for arithmetics, or as index to "memory array", or both. For example:
Code:
mov eax, 4   ;set EAX register to 4
mov ebx, [eax]  ;read memory at address 4 to EBX
mov ebx, [4]      ;same as previous
    


Another things which could be troublesome until explained is accessing various parts of register. For exampe EAX is 32 bit register, whose lower 16 bits are called AX. Lower 8 bits of AX is called AL, and upper 8 bits of AX is called AH. You can access these register parts directly:
Code:
mov eax, 0x12345678   ;EAX = 12345678
mov al, 0xAB   ;EAX = 123456AB
mov ah, 0xCD   ;EAX = 1234CDAB
mov ax, 0x0000 ;EAX = 12340000
    
Post 06 Oct 2008, 09:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
iceman90289



Joined: 06 Oct 2008
Posts: 5
Location: California
iceman90289 07 Oct 2008, 02:05
ah ok. i see how eax works. thank you. that did help a lot.
Post 07 Oct 2008, 02:05
View user's profile Send private message AIM Address MSN Messenger 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.