Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assembly Programming Notes for Practical2 Munaf Sheikh

Similar presentations


Presentation on theme: "Assembly Programming Notes for Practical2 Munaf Sheikh"— Presentation transcript:

1 Assembly Programming Notes for Practical2 Munaf Sheikh

2 Stub Program

3 Data representation Electrical current has two states (on or off) Electrical current has two states (on or off) Binary used to represent the states Binary used to represent the states (1 = on, 0 = off)  bits Octal (0 to 8)  bytes Octal (0 to 8)  bytes Hexadecimal (0 to F) used when binary strings get TOO long Hexadecimal (0 to F) used when binary strings get TOO long

4 Operations on binary Add Add –101 ADD 110 = 011 overflow 1 Subtract Subtract –101 SUB 110 = And And –101 AND 110 = 100 Or Or –101 OR 110 = 111 Not Not –Not 101 = 010

5 CPU Registers Central Processing Unit (CPU) ALUCUCLOCK IO Devices #1… #N Memory Storage Unit Control bus Address bus Data bus

6 Registers Registers are named locations within the CPU that can be accessed VERY quickly Registers are named locations within the CPU that can be accessed VERY quickly –General Purpose –Segment –Pointer –Index

7 General-Purpose Registers AX Accumulator Register mostly used for calculations and for input/output AX Accumulator Register mostly used for calculations and for input/output BX Base Register Only register that can be used as an index BX Base Register Only register that can be used as an index CX Count Register register used for the loop instruction CX Count Register register used for the loop instruction DX Data Register input/output and used by multiply and divide DX Data Register input/output and used by multiply and divide

8 Pointer Registers IP Instruction Pointer 16-bit number that points to the offset of the next instruction IP Instruction Pointer 16-bit number that points to the offset of the next instruction SP Stack Pointer 16-bit number that points to the offset that the stack is using SP Stack Pointer 16-bit number that points to the offset that the stack is using BP Base Pointer used to pass data to and from the stack BP Base Pointer used to pass data to and from the stack

9 Segment Registers CS Code Segment 16-bit number that points to the active code-segment CS Code Segment 16-bit number that points to the active code-segment DS Data Segment 16-bit number that points to the active data-segment DS Data Segment 16-bit number that points to the active data-segment SS Stack Segment 16-bit number that points to the active stack-segment SS Stack Segment 16-bit number that points to the active stack-segment ES Extra Segment 16-bit number that points to the active extra-segment ES Extra Segment 16-bit number that points to the active extra-segment

10 Index Registers SI Source Index used by string operations as source SI Source Index used by string operations as source DI Destination Index used by string operations as destination DI Destination Index used by string operations as destination

11 Basic Elements of Assembly Integer Constants Integer Constants 26; 26d (decimal); 42o (octal); 1Ah (hex) Integer Expressions Integer Expressions -(3+4) * (6-1) Real Number Constants Real Number Constants 2.0; +3.0; -44.2E+05; 26E5 Character Constants Character Constants ‘A’; “d” String Constants String Constants ‘ABC’; ‘X’; “Hello World”; ‘4096’;

12 Basic Elements (cnt..) Reserved Words Reserved Words –Instruction mnemonics –Directives –Attributes –Operators –Predefined Symbols Identifiers Identifiers Programmer chosen name: identifier, constant, procedure, code lable Directives Directives.data;.code; …

13 Basic Elements (cnt..) Instructions Instructions –Label (optional) –Instruction Mnemonic (required) –Operands (usually required) –Comment (optional) Eg: Eg: target: mov ax, bx …. jmp target Eg: mov ax, myVariable Eg: mov ax, myVariable Label:MnemonicOperands ; Comment

14 Intel Instruction set Add dest, src Add dest, src Sub dest, src Sub dest, src And dest, src And dest, src Or dest, src Or dest, src Not dest Not dest Mul src Mul src

15 Prac 2 Irvine16 library provides functions that can be used in your programs Irvine16 library provides functions that can be used in your programs Declaring prototypes for library functions Declaring prototypes for library functions Crlf PROTO Readstring PROTO Readint PROTO Writestring PROTO Writeint PROTO

16 Prac 2 (cnt..) – writing strings userprompt db "What's your name:",0 userprompt db "What's your name:",0 ; prompt for uname (.data) mov dx, offset userprompt mov dx, offset userprompt ; point dx, to address of for display Invoke Writestring Invoke Writestring ; display (function in IRVINE library) dx: data register, used for input/output of text

17 Prac 2 (Cnt..) – writing ints anumber dw ? anumber dw ? ; integer (.data) mov ax, anumber mov ax, anumber ; copy to AX register for display invoke Writeint invoke Writeint ; display AX register as signed-integer ax: accumulator register, used for calculations and input/output

18 Prac 2 (cnt..) – reading strings uname db 50 dup(0) uname db 50 dup(0) ; string (.data) mov dx, offset uname mov dx, offset uname ; point dx, to address of input var ; point dx, to address of input var invoke Readstring ; read input as string into ; read input as string into

19 Prac 2 (cnt..) – reading ints anumber dw ? anumber dw ? ; integer (.data) invoke Readint ; read input as 16bit integer (input in register AX) mov anumber, ax mov anumber, ax ; copy read in integer into ; copy read in integer into

20 Due date: Not later than 23:59: /02/2005 Not later than 23:59: /02/2005


Download ppt "Assembly Programming Notes for Practical2 Munaf Sheikh"

Similar presentations


Ads by Google