228-10week7-1 - SOEN228 Week 7 Programmers Model Registers...

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

View Full Document Right Arrow Icon
SOEN228 Week 7
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 ebx,4 loop addnext shr eax,6
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
The .bss segment This section is for the declaration of variables. use RESB, RESW, RESD, RESQ and REST pseudocodes to reserve uninitialized space in memory for variables: example segment .bss filename: resb 255 ; Reserve 255 bytes number: resb 1 ; Reserve 1 byte bignum: resw 1 ; Reserve 1 word (1 word = 2 bytes) realarray: resq 10 ; Reserve an array of 10 reals
Background image of page 8
The .text segment This is where the actual assembly code is written. The .text section must begin with the declaration global _start, which tells the kernel where the program execution begins. Example segment.text global _start _start: pop ebx ; Here is the where the program actually begins . .
Background image of page 9

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

View Full DocumentRight Arrow Icon
Hello World program segment .data ;data segment msg db ‘Hello World! PleaseType Your ID’, 0xA len equ $ - msg ; length of message segment .bss ;uninitialized data id resb 10 ; reserve 10 bytes for segment .text ; code segment global _start ; global program name _start: ; program entry mov eax, 4 ; select kernel call #4 mov ebx, 1 ; default output device mov ecx, msg ; second argument: pointer ; to message mov edx, len ; third argument: length int 0x80 ; invoke kernel call to mov eax, 3 ; select kernel call #3 mov ebx, 0 ; default input device
Background image of page 10
Image of page 11
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 / 45

228-10week7-1 - SOEN228 Week 7 Programmers Model Registers...

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

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