Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP2011 Assembly Language Programming and Introduction to WRAMP.

Similar presentations


Presentation on theme: "COMP2011 Assembly Language Programming and Introduction to WRAMP."— Presentation transcript:

1 COMP2011 Assembly Language Programming and Introduction to WRAMP

2 COMP201 2 Introduction In previous lectures we have been looking at how data is stored in a computer We will now take a look at how a computer operates In “Stored Program” computers, the most common type, the computer “executes” a “program” created by the programmer The level of abstraction where we can best examine the workings of the computer is at the “assembly language” level  E.g. add $3,$4,$5 “C” assembler Machine code CPU

3 COMP201 3 Why Assembly Assembly language is used for:  Hand optimisation of commonly used code (now rare as modern optimising compilers are very good)  Machine dependent parts of operating systems.  Device drivers  Some embedded devices with limited memory and simple functionality. Most programmers do not use assembly. It is taught to provide understanding of the CPU.

4 COMP201 4 Binary vs. assembler The computer itself operates on binary numbers. Programming in binary is extremely difficult; to ease this, assembler language was invented. Assembler uses mnemonics to aid the programmer; an additional step is then required, to translate the assembler into binary for the computer—each CPU is different MOV AL,[0200] becomes A0 0002 (8086 assembler) Op code Address (LSB first)

5 COMP201 5 Components of a Programming Language  All programming languages must be able to specify four types of operations: Movement of data;  Must be able to handle various data types Arithmetic operations  e.g. sum = a + b - c; Conditional execution  e.g. while (count =1; count < 10; count++;) {…} if (a < b) c=c+1; else c=c-1; Input and Output.  e.g. Printf (“Total %i\n”,sum);

6 COMP201 6 Why WRAMP? Most Computer Instruction sets are optimised for performance or backwards compatibility  Tends to make them very complex and hard to learn WRAMP was designed specifically for teaching purposes  Allows us to focus on the main concepts rather than a particular manufacturer’s quirks Very few people will program extensively in assembler but it is studied so that you can better understand CPU operation.

7 COMP201 7 WRAMP Waikato RISC Architecture Microprocessor Features:  RISC architecture  32 bit data paths  Load/Store memory architecture –limited addressing modes  Three operand format for instructions  Regularity of instructions  Described in VHDL, and implemented in Xilinx FPGA device.  A part of REX, a laboratory exercise machine with WRAMP processor.  Connected to workstation in labs.  Displays for contents of buses.  More: see Exercise 2 (on web page 24/3).

8 COMP201 8 WRAMP Will use a number of C examples to introduce WRAMP, so the desired operation is clear. Starting with arithmetic operations (+,-,*,/) Generally an assembly language instruction can carry out a single operation, that is… There is a 1:1 mapping between assembler instructions and their binary equivalents sum = a + b; “C” add sum, a, b “pseudo assembler” Exact syntax depends upon processor

9 COMP201 9 Consider: Where are the variables stored? sum = a + b - c; “C” add temp, a, b sub sum, temp, c “pseudo assembler” add 0x104, 0x100, 0x101 sub 0x103, 0x104, 0x102 “pseudo assembler” a b c sum 0x100 0x101 0x102 0x103 temp 0x104 Memory locations

10 COMP201 10 Instruction Sizes Consider the amount of memory to store the instruction: add a,b,c Number of bits to store an opcode dependent on number of instructions in instruction set--- e.g. 8 bits => 2 8 or 256 instructions (max)…and 6 bits => 64 instructions Operand fields contain addresses of variables being accessed (32 bits per operand) Therefore, instruction size = 8 + (3 * 32) = 102 bits Clearly, something must be done to limit this…

11 COMP201 11 Instruction Sizes (continued)  To execute this instruction would require: 4 memory references to fetch instruction 3 memory references to execute instruction  Several techniques are used which minimize this problem… among them: Use small, local memory (e.g. registers) to store variables Use registers as pointers to memory, instead of directly addressing memory.

12 COMP201 12 Registers  NOTE: Operations inside a processor are significantly faster than those outside, so an operand stored in local memory (registers) can be accessed more quickly than an operand in main memory. Registers analogous to a Nickname (E.g. Palmerston North often referred to as Palmy)  Have to be careful to avoid running out of this local memory; also ambiguity is possible (registers are used for storing many variables at different times during program execution)

13 COMP201 13 Registers  Possibilities: Identify locations referenced frequently and give them a shorter address (sometimes within a given page of memory) create a second small memory (called a register file) to store frequently accessed variables  e.g. 16 word register file requires 4 bit address for any given register, instead of the 32 bits earlier required. Use register contents to point to address within memory, where desired quantity is stored. Sometimes used in conjunction with an offset, allowing access to a block of memory, where a group of data items is stored.

14 COMP201 14 Using registers as pointers to memory Register 1 More registers -16 total 4 bits All of memory 2 32 locations 32 bits Points to a register Points to a memory location Desired contents

15 COMP201 15 Registers (continued)  $i refers to i th word of this memory Instruction add a, b, c could be represented as add $1, $2, $3  As $ predetermined then only need to store 4 bits for each operand, the name of the register where it is stored.  NOTE: values of a,b,c, are encoded in instruction… i.e. the instruction may be different for add $1, $2, $3 and for add $4, $5, $7 0000RdRd RsRs 0000000000000000 RtRt Register number (0-15)

16 COMP201 16 Registers  As an example, WRAMP has a register file.  This register file is small enough to be stored inside a modern CPU Further reduces number of main memory references, with corresponding speed increase. 0 $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $sp ($14) $ra ($15) $13 31 0 Available for general use Stack pointer Ret address Always 0

17 COMP201 17 Registers  The WRAMP register file has 13 general purpose registers which can be used for whatever temporary storage you need in your program…  But you need to keep track of what variable is stored where! So, make a copy of this page, and allocate your storage space… 0 $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $sp ($14) $ra ($15) $13 31 0 Available for general use

18 COMP201 18 Monitor Commands When running the REX boards, WRAMPmon is the program that interprets your keystrokes into WRAMP actions. The monitor program only responds to certain commands (see web page… resources for the manual) The commands are repeated here, for convenience. load go [address] cont dis [start addr [end]] vm vr [reg] sr sb vb rb s so help or ?

19 COMP201 19 Troubleshooting WRAMP Your major assets for troubleshooting WRAMP are:  A register map  A list of your program  Breakpoints (which you set/reset)  Viewing registers  Program knowledge WRAMP Troubleshooting Aid PC$0$1$2$3 $4$5$6$7 $8$9$10$11 $12$13$sp$ra


Download ppt "COMP2011 Assembly Language Programming and Introduction to WRAMP."

Similar presentations


Ads by Google