CIS-77 Home http://www.c-jump.com/CIS77/CIS77syllabus.htm
An assembler or compiler is just another program that executes on your computer system.
The only thing special about an assembler or compiler is that it translates programs from one form (source code) to another (machine code).
A typical x86 assembler, for example, would read lines of text with x86 instructions, parse each statement, and then write the binary equivalent of each instruction directly to memory or to a file for later execution.
Assemblers have two big advantages over coding in machine code:
First, they automatically translate strings like
add ax, bx mov ax, [1000h]
to their corresponding binary form.
Second, and probably even more important, assemblers let you attach labels to statements and refer to them in jump instructions
(a programmer does not have to know the target address of an instruction when specifying targets of jump instructions.)
|
|
|
|
; add_16_bytes.asm ; .586P ; Flat memory model, standard calling convention: .MODEL FLAT, STDCALL ; ; Data segment _DATA SEGMENT values db 16 DUP( 5 ) ; 16 bytes of values "5" _DATA ENDS ; Code segment _TEXT SEGMENT START: mov eax, 0 ; clear result mov bl, 16 ; init loop counter lea esi, values ; init data pointer addup: add al, [esi] ; add byte to sum inc esi ; increment data pointer dec bl ; decrement loop counter jnz addup ; if BL not zero, continue mov [esi], al ; save sum ret ; Exit _TEXT ENDS END START
Listing file: add_16_bytes.lst
To assemble and run an assembler program named myprog.asm, type the following commands:
call "C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat" ML /coff /c /Fl myprog.asm LINK /debug /subsystem:console /entry:start /out:myprog.exe myprog.obj ..\iolib\io.obj kernel32.lib myprog.exe
|
|
|
|
After loading the executable file into memory, the operating system:
Creates the program segment prefix (PSP) header in memory.
Allocates memory for the program, based on the values in the PSP.
Loads the program.
Calculates the correct values for absolute addresses from the relocation table.
Loads the segment registers SS, CS, DS, and ES with values that point to the proper areas of memory.
DUMPBIN disassembly program
Debuggers: OllyDbg and WinDbg
Consol I/O: iolib.