lecture01 - 0306-250 Assembly Language Programming Lecture...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Lecture One: Introduction • Course Description • Course Motivation • Assembly Language Program Structure • Data Representation Course Information Resources myCourses.rit.edu www.ce.rit.edu Ø Student Resources Ø Course Reference Materials ØEECC 250 Syllabus Schedule Laboratory Report Guidelines 2 Why Assembly Language? Lowest level programming • Closest to hardware Direct correspondence to machine instruction set • 1 assembly language instruction = 1 machine instruction 3 Assembly language is on the boundary between HW and SW. • • Interpreted vs. compiled JAVA vs. other HLLs C++ Source JAVA Source 68000 C Compiler ASM Source 8086 ASM Sparc ASM Machine Code JVM ASM Source 68000 ASM JAVA byte codes SParc C Compiler ASM Source JAVA Compiler 8086 C Compiler Machine Code Machine Code 68000 8086 SParc JVM 68000 Sparc JVM 8086 Material from Dr. F. Hu, EECC 250. 4 Hierarchy of Computer Architecture High-Level Language Programs Software Application Operating System Machine Language Program Software/Hardware Boundary Assembly Language Programs Compiler Firmware Instr. Set Proc. I/O system BIOS (Basic Input/Output System) Instruction Set Architecture (ISA) Datapath & Control Hardware Digital Design Circuit Design Microprogram Layout Logic Diagrams VLSI placement & routing Circuit Diagrams Material used with permission from Dr. M. Shaaban, Dept. of Comp. Eng., RIT. Register Transfer Notation (RTN) The ISA forms an abstraction layer that sets the requirements for both complier and CPU designers. 5 Assembly Language Applications Precise hardware control • Device drivers System software • Operating systems, device drivers, compilers Precise timing (Accuracy) Memory constrained, embedded systems • Real-time systems Extreme performance • Application-specific libraries – Graphics, scientific, etc. 6 Design Methodology Flow control Outlines Top-down (hierarchical) design Procedural —not object-oriented 7 HCS12 Block Diagram MC9S12C Family Reference Manual, p. 20 8 HCS12 CPU Registers • Two 8-bit accumulators: A, B Can be concatenated as 16-bit accumulator: D • Two 16-bit index registers: X, Y • 16-bit stack pointer: SP • 16-bit program counter: PC • 8-bit condition code register: CCR S12CPUV2 Reference Manual, p. 21 9 Lecture1.asm (page 1 of 3) TITLE "Lecture 1 Example" MLIST ON ;********************************************************************** ; Lecture 1 example program ; Demonstrates general HCS12 assembly program structure. ; ; Name: Roy W. Melton ; Date: September 7, 2009 ; Class: 0306-250 ;********************************************************************** ; export symbols XDEF Entry, main ; Allows "Entry" to be refereneced either ; in the linker .prm file or from C/C++ XREF __SEG_END_SSTACK ; symbol defined by linker for end of stack ;********************************************************************** ; include derivative specific macros INCLUDE 'mc9s12dt256.inc' ;********************************************************************** 10 Lecture1.asm (page 2 of 3) ;********************************************************************** ; Code ; The beginning of ROM ; Code begins here followed immediately by program constants ; MyCode: SECTION directive determines the address in memory ; via linker parameter (.prm) file. MyCode: SECTION ; "main" is the name of the program ; "main" and "Entry" are used with linker to start execution here main: Entry: ; Each instruction (or group of instructions) should be commented... ldaa #255 ; The program is written here... ldab #5 ; etc.... * Program "termination" bra * 11 Lecture1.asm (page 3 of 3) ;********************************************************************** ; Constants ; MyConst: SECTION directive places constants in ROM just after code MyConst: SECTION ; Place constant data here LIST: DC.B 4 DC.W 4 DC.L 4 DC.B -1 DC.W -1 DC.L -1 ;********************************************************************** ; Variables ; MyData: SECTION directive places variables in RAM MyData: SECTION Buffer: DS.B 16 ; Two bytes of storage ; ; The END directive stops assembly; no subsequent statements processed END 12 Lecture1.lst (page 1 of 3) Lecture 1 Example Freescale HC12-Assembler (c) Copyright Freescale 1987-2009 Abs. Rel. ---- ---1 1 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 Loc Obj. code ------ --------- Source line ----------TITLE "Lecture 1 Example" ;********************************************************************** ; Lecture 1 example program ; Demonstrates general HCS12 assembly program structure. ; ; Name: Roy W. Melton ; Date: September 7, 2009 ; Class: 0306-250 ;********************************************************************** ; export symbols XDEF Entry, main ; Allows "Entry" to be refereneced either ; in the linker .prm file or from C/C++ XREF __SEG_END_SSTACK ; symbol defined by linker for end of stack ;********************************************************************** ; include derivative specific macros INCLUDE 'mc9s12dt256.inc' 13 Lecture1.lst (page 2 of 3) 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 000000 86FF 000002 C605 000004 20FE ;********************************************************************** ; Code ; The beginning of ROM ; Code begins here followed immediately by program constants ; MyCode: SECTION directive determines the address in memory ; via linker parameter (.prm) file. MyCode: SECTION ; "main" is the name of the program ; "main" and "Entry" are used with linker to start execution here main: Entry: ; Each instruction (or group of instructions) should be commented... ldaa #255 ; The program is written here... ldab #5 ; etc.... * Program "termination" bra * 14 Lecture1.lst (page 3 of 3) 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 000000 000001 000003 000007 000008 00000A 000000 04 0004 0000 0004 FF FFFF FFFF FFFF ;********************************************************************** ; Constants ; MyConst: SECTION directive places constants in ROM just after code MyConst: SECTION ; Place constant data here LIST: DC.B 4 DC.W 4 DC.L 4 DC.B -1 DC.W -1 DC.L -1 ;********************************************************************** ; Variables ; MyData: SECTION directive places variables in RAM MyData: SECTION Buffer: DS.B 16 ; Two bytes of storage ; ; The END directive stops assembly; no subsequent statements processed 15 Lecture1.map (page 1 of 2) *** EVALUATION *** PROGRAM "C:\Documents and Settings\rwmeec\My Documents\Class\250\20091\Example\Example\bin\Project.abs" ********************************************************************************************* TARGET SECTION --------------------------------------------------------------------------------------------Processor : Freescale HC12 Memory Model: SMALL File Format : ELF\DWARF 2.0 Linker : SmartLinker V-5.0.36 Build 9056, Feb 26 2009 ********************************************************************************************* FILE SECTION --------------------------------------------------------------------------------------------Example.asm.o Model: SMALL, Lang: Assembler ********************************************************************************************* STARTUP SECTION --------------------------------------------------------------------------------------------Entry point: 0xC000 (Entry) ********************************************************************************************* SECTION-ALLOCATION SECTION Section Name Size Type From To Segment --------------------------------------------------------------------------------------------.init 6 R 0xC000 0xC005 ROM_C000 .stack 256 R/W 0x1000 0x10FF RAM .vectSeg0_vect 2 R 0xFFFE 0xFFFF .vectSeg0 Summary of section sizes per section type: READ_ONLY (R): 8 (dec: 8) READ_WRITE (R/W): 100 (dec: 256) 16 Lecture1.map (page 2 of 2) ********************************************************************************************* VECTOR-ALLOCATION SECTION Address InitValue InitFunction --------------------------------------------------------------------------------------------0xFFFE 0xC000 Entry ********************************************************************************************* OBJECT-ALLOCATION SECTION Name Module Addr hSize dSize Ref Section RLIB --------------------------------------------------------------------------------------------MODULE: -- Example.asm.o -- PROCEDURES: Entry C000 6 6 0 .init main C000 0 0 0 .init - VARIABLES: ********************************************************************************************* MODULE STATISTIC Name Data Code Const --------------------------------------------------------------------------------------------Example.asm.o 0 6 0 other 256 2 0 ********************************************************************************************* SECTION USE IN OBJECT-ALLOCATION SECTION --------------------------------------------------------------------------------------------SECTION: ".init" main Entry ********************************************************************************************* OBJECT LIST SORTED BY ADDRESS Name Addr hSize dSize Ref Section RLIB --------------------------------------------------------------------------------------------main C000 0 0 0 .init Entry C000 6 6 0 .init 17 Data Representation • Binary numbers • Hexadecimal numbers • Two’s complement • Binary coded decimal numbers • ASCII characters Number Systems Positional: each digit position is related to the next by a constant multiplier, the base or radix of the system n -1 Numberr = å d i r i = d n-1r n-1 + d n-2 r n-2 + K + d1r1 + d 0 r 0 i =0 • di: ith digit counting from the right, starting with 0 • n: number of digits • r: radix (base) of the number system • Expanded notation: format at right of equation above • Standard notation: dn-1dn-2. . .d1d0 (i.e., just digits) One way to convert between bases is to compute the expanded form in the new base. 19 Conversion between Bases through Expanded Notation Example 1: Convert 10110102 to base 10. (i.e., binary to decimal conversion) ( ) 10110102 = 1´ 26 + 1´ 2 4 + 1´ 23 + 1´ 21 10 = (64 + 16 + 8 + 2)10 = 9010 Example 2: Convert 6510 to base 2. (i.e., decimal to binary conversion) ( 6510 = [110] ´ [1010]1 + [101] ´ [1010]0 ) 2 = (111100 + 101) 2 = 10000012 20 Division-Remainder Method of Number Conversion Algorithm to convert Number to base r Dividend ¬ Number i¬0 repeat Divide Dividend by r Dividend ¬ resulting integer quotient Digit i ¬ resulting integer remainder i++ until Dividend == 0 n -1 Numberr = å d i r i = d n-1r n-1 + d n-2 r n-2 + K + d1r1 + d 0 r 0 i =0 Remainders from successive division by r are digits in base r starting with d0 and ending with dn-1 21 Conversion from Decimal to Hex with Division-Remainder Method Example: Convert 6510 to base 16. (i.e., decimal to hex conversion) r Divisor 16 65 4 0 Remainder Position 1 0 4 1 22 Conversion from Decimal to Binary with Division-Remainder Method Example: Convert 9010 to base 2. (i.e., decimal to binary conversion) r Divisor 2 90 Remainder Position 45 22 11 0 1 0 0 1 2 5 2 1 1 1 0 3 4 5 0 1 6 23 Double-Dabble Method of Number Conversion Algorithm to convert n-digit Number from base r NewNumber ¬ 0 i¬n repeat i¬i-1 NewNumber ¬ NewNumber ´ r NewNumber ¬ NewNumber + digit i until i = 0 n -1 Numberr = å d i r i = d n-1r n-1 + d n-2 r n-2 + K + d1r1 + d 0 r 0 i =0 24 Convert from Hex to Decimal with Double-Dabble Method Example: Convert 5A16 to base 10. (i.e., hex to decimal conversion) 5 A ´16 80 + 10 = 90 25 Convert from Binary to Decimal with Double-Dabble Method Example: Convert 10000012 to base 10. (i.e., binary to decimal conversion) 1 0 0 0 0 0 1 ´2 2 +0= 2 ´2 4 +0 = 4 ´2 8 +0 =8 ´2 16 + 0 = 16 ´2 32 + 0 = 32 ´2 64 + 1 = 65 26 Relationship between Binary and Hex • 24 = 16 • Four binary digits correspond to one hex digit • One hex digit corresponds to four binary digits Decimal Binary Hex Decimal Binary Hex 0 0000 0 8 1000 8 1 0001 1 9 1001 9 2 0010 2 10 1010 A 3 0011 3 11 1011 B 4 0100 4 12 1100 C 5 0101 5 13 1101 D 6 0110 6 14 1110 E 7 0111 7 15 1111 F 27 Computer Data Are Binary • Computer storage is in bits • Each bit is a 0 or a 1 • Anything digital is a set of bits (regardless of content format) – – – – – Numbers Characters Documents Pictures Sounds 28 Signed Numbers Signed integers are in 2’s complement format • Meaningful only for a fixed number of bits, n • Most significant bit indicates sign • Positive numbers – Binary magnitude – 0 sign bit (MSB) • Negative numbers – Two’s complement of binary magnitude – 1 sign bit (MSB) n -1 Numberr = -2 n + å d i r i = -d n-1 2 n-1 + d n-2 2 n-2 + K + 21 r1 + 20 r 0 i =0 29 “Two’s Complement” • Used as a noun: a number representation – Refers to signed binary number format – Number may be positive or negative • Used as a verb: sign change – Refers to taking the two’s complement – Result is of opposite sign – Involves 2-step process 1. Take the one’s complement (i.e., invert all of the bits) 2. Then add one 30 Two’s Complement Examples Determine the 8-bit signed representation of these integers. A. 65 01000001 B. -65 10111110 + 1 10111111 31 Two’s Complement Arithmetic Determine the results of the following arithmetic operations. A. $41 + $BF $41 %01000001 +%10111111 +$BF 00 %00000000 No overflow (i.e., result is valid)—positive plus negative B. $5A + $BF $5A %01011010 +$BF %10111111 $19 %00011001 No overflow (i.e., result is valid)—positive plus negative No knowledge of magnitude is necessary—just add. 32 Signed versus Unsigned Representations • Unsigned n-bit representation – All n bits used for magnitude – n-bit number Î [0, 2n - 1] – 2n possible numbers • Signed n-bit representation – – – – 1 bit used for sign n - 1 bits used for magnitude n-bit number Î [-2n - 1, 2n - 1 - 1] 2n possible numbers 33 ASCII Character Values • ASCII code is character binary representation – One byte (i.e., 8 bits) per character – 256 possible characters • Example: Express character A in ASCII – 65 – %01000001 – $41 • Example: What ASCII character is %01011010 –Z 34 ASCII Character Table • American Standard Code for Information Interchange (ASCII) • ASCII code is binary representation for character – One byte (i.e., 8 bits) per character – 256 possible characters 35 ASCII Table S12CPUV2 Reference Manual, p. 401. 36 ASCII Math • Convert ASCII code for decimal digit to binary value of decimal digit AND with $0F – '0' = $30 – '9' = $39 • Convert binary value of decimal digit to ASCII code of decimal digit OR with $30 • Convert upper-case character to lower case – – Add 32 Add ('a' - 'A') • Convert lower-case character to upper case – – Subtract 32 Add ('A' - 'a') 37 ...
View Full Document

This note was uploaded on 05/06/2010 for the course EECC 0306-250 taught by Professor Roymelton during the Fall '10 term at RIT.

Ask a homework question - tutors are online