Many of you, if you are like me, might be interested in how assembly works. You will be very surprised that assembly is very very easy, especially after you write a couple of simple programs. But don't get me wrong, you will be frustrated at first, however that frustration, if you channel it right, will lead to serious life long learning and will give you a deeper appreciation of the beauty of assembly.
Working with Data Section
In your .data section, you can declare variables like this:
So, db is define byte, dw is define word, and dd is define double word. Here, byte is 8 bits, word is two bytes, and double word is two words. Basically you used these to define a initialized variables.
Working with BSS Section
In your .bss section, you declare variables like this:
nameOfVariable: resb 256 ;this reserves space for a 256 bytes
nameOfVariable2: resw 1 ;this reserves space for 1 word, otherwise known as 2 bytes
someString: resd 1 ;this reserves space for 1 double word
Working with Text Section
The .text section is your program code. It is what makes a program a program. Simple as that.
You will arrange your instructions in whatever manner to achieve your particular logic goals.
Usually, you will want to have or start with something like this:
global main ;export the symbol main so that external program can see this memory address
Okay so lets get started.
We will be using Netwide Assembler (NASM) to write our program.
The general format of NASM file is this:
The general format of NASM file is this:
;This is a comment
SECTION .data
;declare variable here
SECTION .bss
;declare actual, dynamic variable
SECTION .text
;where your program code/assembly code lives
;
SECTION .data
;declare variable here
SECTION .bss
;declare actual, dynamic variable
SECTION .text
;where your program code/assembly code lives
;
Working with Data Section
In your .data section, you can declare variables like this:
nameOfVariable: db 32 ;this declares a variable names nameOfVariable with byte value of 32
nameOfVariable2: dw 302 ;declare variable of 2 bytes
someString: db "This is an example of a string",10,0 ;we declare an array of string, 10=newline return and 0=termination of array(NULL)
nameOfVariable2: dw 302 ;declare variable of 2 bytes
someString: db "This is an example of a string",10,0 ;we declare an array of string, 10=newline return and 0=termination of array(NULL)
So, db is define byte, dw is define word, and dd is define double word. Here, byte is 8 bits, word is two bytes, and double word is two words. Basically you used these to define a initialized variables.
Working with BSS Section
In your .bss section, you declare variables like this:
nameOfVariable: resb 256 ;this reserves space for a 256 bytes
nameOfVariable2: resw 1 ;this reserves space for 1 word, otherwise known as 2 bytes
someString: resd 1 ;this reserves space for 1 double word
Working with Text Section
The .text section is your program code. It is what makes a program a program. Simple as that.
You will arrange your instructions in whatever manner to achieve your particular logic goals.
Usually, you will want to have or start with something like this:
global main ;export the symbol main so that external program can see this memory address
main: ;here "main:" is a label--labels are an alias for memory address
;setup our stack frame
push ebp
mov ebp, esp
;clean u stack frame
mov esp, ebp
pop ebp
ret
Comments
Post a Comment