1 / 20

Assembly Programming

Assembly Programming. Notes for Practical2 Munaf Sheikh http://www.cs.uwc.ac.za/~msheikh/COS365Assembler. Stub Program. Data representation. Electrical current has two states (on or off) Binary used to represent the states (1 = on, 0 = off)  bits 100100100111010110100100100100001

keala
Download Presentation

Assembly Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assembly Programming Notes for Practical2 Munaf Sheikh http://www.cs.uwc.ac.za/~msheikh/COS365Assembler

  2. Stub Program

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

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

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

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

  7. General-Purpose Registers • AXAccumulator Register mostly used for calculations and for input/output • BXBase Register Only register that can be used as an index • CXCount Register register used for the loop instruction • DXData 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 • SPStack Pointer 16-bit number that points to the offset that the stack is using • BPBase Pointer used to pass data to and from the stack

  9. Segment Registers • CSCode Segment 16-bit number that points to the active code-segment • DSData Segment 16-bit number that points to the active data-segment • SSStack Segment 16-bit number that points to the active stack-segment • ES Extra Segment 16-bit number that points to the active extra-segment

  10. Index Registers • SISource Index used by string operations as source • DIDestination Index used by string operations as destination

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

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

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

  14. Intel Instruction set • Add dest, src • Sub dest, src • And dest, src • Or dest, src • Not dest • Mul src • http://www.penguin.cz/~literakl/intel/intel.html

  15. Prac 2 • Irvine16 library provides functions that can be used in your programs • 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   ; prompt for uname (.data) mov dx, offset userprompt ; point dx, to address of <userprompt> for display InvokeWritestring  ; display <userprompt> (function in IRVINE library) dx: data register, used for input/output of text

  17. Prac 2 (Cnt..) – writing ints anumber dw ?   ; integer <anumber> (.data) mov ax, anumber ; copy <anumber> to AX register for display 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)  ; string <uname> (.data) mov dx, offset uname ; point dx, to address of input var <uname> invoke Readstring ; read input as string into <uname>

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

  20. Due date: • Not later than 23:59:59.99999 22/02/2005

More Related