week_8_intro_to_assembly_programming

week_8_intro_to_assembly_programming - SOEN 228 Intro to...

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

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

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

View Full Document Right Arrow Icon
Programmers Model
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
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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 .
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
Image of page 7

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

View Full Document Right 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)
Image of page 8
More directives Double quotes and single quotes are treated the same. Consecutive data definitions are stored sequentially in memory. L2 is stored immediately after L1 in memory. Sequences of memory may also be defined. Label9 db 0, 1, 2, 3 ; defines 4 bytes Label10 db "w", "o", "r", ’d’, 0 ; defines a C string = ;"word" Label11 db ’word’, 0 ; same as Label10 Label12 times 100 db 0 ; equivalent to 100 (db 0)’s Label13 resw 100 ; reserves room for 100 words
Image of page 9

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

View Full Document Right Arrow Icon
Addresses Segment .data ; data segment msg db 'The number is: ' ……..
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern