week_8_intro_to_assembly_programming

week_8_intro_to_assembly_programming - SOEN 228 Intro to...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
SOEN 228 Intro to Assembly Language Programming Inter x86 architecture NASM
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programmers Model
Background image of page 2
Registers General Registers eax, edx, ecx, ebx, ebp, esi, edi, esp Each is 32-bit wide. Each lower half (the less significant 16 bits) is given a distinct name (for 16 bit manipulations): ax, dx, cx, bx, ax to dx are further subdivided to 8 bit registers, specifically: ax = ah : al (: denotes concatenation), dx = dh: dl cx = ch: cl, bx = bh: bl For example, we can choose to use: • ax to hold an integer of 16 bits • ah or al to hold a single ASCII coded character • eax to hold an integer of 32 bits • eax to hold a character string of 4 ASCII characters
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Special uses of registers ecx can be used as a loop counter (loop instruction: ecx=ecx-1, jump to label if not 0) Other registers: Esi: source index Edi: destination index Ebp: base pointer Esp stack pointer
Background image of page 4
Assembly example mov ecx,64 mov eax,0 mov esi,0 mov ebx, marks addnext add eax, [ebx+esi] inc esi,4 loop addnext shr eax,6 // divide by 64
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Parts of an Assembly Program An assembly program can be divided into three sections: The .data segment The .bss segment The .text segment But note: this was necessary for 16 bit addressing. You don’t need it for 32 bit addressing, but it s often included .
Background image of page 6
The .data segment This section is for declaring initialized data. The data does not change at runtime The .data section is used for filenames, buffer sizes, and constants using the EQU instruction. Data can also be defined using the DB, DW, DD, DQ and DT instructions. For example: segment .data message: db 'Hello world!' ; Declare message to contain the bytes 'Hello world!' (without quotes) msglength: equ 12 ; Declare msglength to have the constant value 12 \buffersize: dw 1024 ; Declare buffersize to be a word containing 1024
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data directives used in data segments to define room for memory. Defined data: DX directives Reserved space with an initial value: RESX directives X is a letter that specifies the size of the object(s) that will be stored Normally memory locations are marked with labels. Labels allow Programs to refer to memory locations in code. several examples: Label1 db 0 ; byte labeled L1 with initial value 0 Label2 dw 1000 ; word labeled L2 with initial value 1000 Label3 db 110101b ; byte initialized to binary 110101 ;(53 in decimal) Label4 db 12h ; byte initialized to hex 12 (18 in decimal) Label5 db 17o ; byte initialized to octal 17 (15 in decimal) Label6 dd 1A92h ; double word initialized to hex 1A92 Label7 resb 1 ; 1 uninitialized byte Label8 db "A" ; byte initialized to ASCII code for A (65)
Background image of page 8
More directives Double quotes and single quotes are treated the same. Consecutive data definitions are stored
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/30/2011 for the course SOEN 228 taught by Professor T.fancott during the Winter '11 term at Concordia Canada.

Page1 / 43

week_8_intro_to_assembly_programming - SOEN 228 Intro to...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online