More on Assembly CS 210 Tutorial 4. Detail of Echo program entry main.enter; import "../IMPORT/callsys.h"; block main uses CALLSYS { code { public enter:

Slides:



Advertisements
Similar presentations
Fundamentals of Computer and programming in C Programming Languages, Programs and Programming Rohit Khokher.
Advertisements

OutLine of Tutorial 3 Memory Allocation Const string New string(byte array) Read memory in simulator Function invocation How Import library files Modify.
Goal: Write Programs in Assembly
OutLine of Tutorial 5 Summary of Load/Store instructions Exercises reading memory in Simulator Exercises writing code.
The 8051 Microcontroller and Embedded Systems
There are two types of addressing schemes:
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
SPARC Architecture & Assembly Language
I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
MIPS Assembly Language Programming
1 Computer Architecture MIPS Simulator and Assembly language.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lecture 8: MIPS Instruction Set
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
S. Barua – CPSC 240 CHAPTER 5 THE LC-3 Topics Memory organization Registers Instruction set Opcodes.
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
Computer Organization and Architecture Tutorial 2 Kenneth Lee.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Chapter 2 Software Tools and Assembly Language Syntax.
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
MIPS coding. SPIM Some links can be found such as:
1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h  Int 21 –A hexadecimal.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
Registers and MAL Lecture 12. The MAL Architecture MAL is a load/store architecture. MAL supports only those addressing modes supported by the MIPS RISC.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Functions in Assembly CS 210 Tutorial 7 Functions in Assembly Studwww.cs.auckland.ac.nz/ ~mngu012/public.html/210/7/
Parul Polytechnic Institute Subject Code : Name Of Subject : Microprocessor and assembly language programming Name of Unit : Instruction cycle.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
X86 Programming Memory Accessing Modes, Characters, and Strings Computer Architecture.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
8086/8088 Instruction Set, Machine Codes and Addressing Modes.
MIPS assembly syntax Home Assignment 3 Assigned. Deadline 2016 February 14, Sunday.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Programming Model CS 333 Sam Houston State University Dr. Tim McGuire.
Internal Programming Architecture or Model
Chapter 7: Low-Level Programming Languages Chapter 7 Low-Level Programming Languages Page 66 In order to execute instructions on a CPU, those instructions.
CS501 Advanced Computer Architecture Lecture 29 Dr.Noor Muhammad Sheikh.
1 Contents: 3.1 Instruction format and Addressing Modes 3.2 Instruction Introduction Chapter 3 Instruction system.
Computer Science 210 tutorial 5
Assembly language.
Addressing Modes in Microprocessors
Data Transfers, Addressing, and Arithmetic
Microprocessor and Assembly Language
MIPS assembly syntax Comments
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Computer Science 210 Computer Organization
Defining Types of data expression Dn [name] expression Dn [name]
Ken D. Nguyen Department of Computer Science Georgia State University
Computer Science 210 Computer Organization
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
Symbolic Instruction and Addressing
Computer Instructions
Chapter 7 Assembly Language
Requirements for coding in Assembly Language
Lecture 6: Assembly Programs
Chapter 6 –Symbolic Instruction and Addressing
Process.
Ken D. Nguyen Department of Computer Science Georgia State University
Presentation transcript:

More on Assembly CS 210 Tutorial 4

Detail of Echo program entry main.enter; import "../IMPORT/callsys.h"; block main uses CALLSYS { code { public enter: { loop: ldiq $a0, CALLSYS_GETCHAR; call_pal CALL_PAL_CALLSYS; blt $v0, end; mov $v0, $a1; ldiq $a0, CALLSYS_PUTCHAR; call_pal CALL_PAL_CALLSYS; br loop; end: } { clr $a1; ldiq $a0, CALLSYS_EXIT; call_pal CALL_PAL_CALLSYS; } } code } block main just specifes the entry point for the program (in other words, where the program starts executing). Like: public static void main(€String[] args) specify that the code in the specified file is imported (included) just specify that we are creating a block of code called main, using some definitions in a block called register that specifies the register numbers for the symbolic names a0, a1, v0, etc, and using some definitions in a block called CALLSYS that specifies the values of CALL_PAL_CALLSYS, CALLSYS_GETCHAR, CALLSYS_PUTCHAR, etc.

Detail of Echo program The lines code {……….. ……………….} code just specify that we are defining code (instructions), rather than data. The assembled bit patterns are placed in the section of memory used for code. The line public enter: labels some code, with the name “enter”. This code can be referred to outside the block, as main.enter.

Detail of Echo program: Label The lines {  loop:  ldiq $a0, CALLSYS_GETCHAR;  call_pal CALL_PAL_CALLSYS;  blt $v0, end;  mov $v0, $a1;  ldiq $a0, CALLSYS_PUTCHAR;  call_pal CALL_PAL_CALLSYS;  br loop;  end: } represent the real work.

Detail of Echo program The line ldiq $a0, CALLSYS_GETCHAR; loads the constant value CALLSYS_GETCHAR (whatever that has been defined to be in the block CALLSYS, in “../IMPORT/callsys.h”) into register a0. The line call_pal CALL_PAL_CALLSYS; then makes a request (rather like a function invocation) to the operating system to do something (read a character from the keyboard). The operating system uses the value in register $a0 todetermine what action to perform (in this case read a character), and returns the result in register $v0. Other parameters to system calls may be passed in registers $a1, $a2, $a3,...

Detail of Echo program The lines mov $v0, $a1; ldiq $a0, CALLSYS_PUTCHAR; call_pal CALL_PAL_CALLSYS; move the character from register v0 into register a1, load the constant value CALLSYS_PUTCHAR into register $a0 (to specify that the action is to write a character), and makes a request to the operating system (to write the character to the screen). The lines { clr $a1; ldiq $a0, CALLSYS_EXIT; call_pal CALL_PAL_CALLSYS; } Cause the program to terminate and control to be returned to the operating system.

Assembly instruction syntax Ex:  addq $t0, $t1, $t3;  subq $t0, 23, $t4; There are five kinds of operands. The opcode determines the number and kind of legal operands: Register, Unsigned 8 bit constant, Register, Brand operation, Unsigned 26 bit constant.  Register: The operand represents a source or destination register. It is written as “$register”, for example, $a0, $v0.  Unsigned 8 bit constant: The second operand of an integer operate instruction can be of this form. The constant is written directly, without any additional annotation, for example 23 in the above subq instruction.

Assembly instruction syntax  Memory address: The operand represents a memory address, computed as a displacement (offset) from a base register. It is written as “displacement($register)”, and means the displacement + contents of integer register $register. The displacement is a signed 16 bit integer. The displacement may be omitted if it is 0, allowing the notation “($register)”. If the register is $zero (register 31), which always contains 0, then the operand can be written with just the displacement. For example, we can write 24($t0). The notation ($t0) is an abbreviation for 0($t0), and the notation 1234 is an abbreviation for 1234($zero). Displacement operands can only be used in load and store instructions.  Branch destination: The operand represents a destination address for a branch instruction. It is written directly as the destination address, but is stored as a displacement from the address just after the branch instruction. The last two bits of the displacement are not stored in the instruction, because they are always 0.  Unsigned 26 bit constant: The operand of a special instruction is of this form. For example, PALL_PAL_CALLSYS in a call_pal instruction.

Load and store instructions To operate on memory values, we must first load the source data from memory, perform the computation, then store the result back in memory. opcode $regA, displacement($regB); Integer load instructions load a number of bytes starting at the specified address ldq (load quadword) loads the 8 bytes corresponding to a quadword, starting at the memory address, into register. ldbu (load byte unsigned) loads a single byte from the memory address, into the low byte of register, making the high 7 bytes zero. stq… stqu…

Run DataRep2 Exercise DATAREP2 Suppose we have memory 0x x abcdef0 0x x x x ldiq $t0, 0x ; ldq $t1, ($t0); stb $t1, 8($t0); ldbu $t2, 2($t0); sll $t2, 56, $t3; sra $t3, 56, $t4; stq $t4, 16($t0);