Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.

Slides:



Advertisements
Similar presentations
I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
Advertisements

1 Computer Architecture MIPS Simulator and Assembly language.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Lecture 2 Introduction to C Programming
Introduction to C Programming
Department of Computer Science and Software Engineering
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
1 Lecture 3: Assembly Language Fundamentals Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#6)
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.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
ZONG Wen Department of Computer Science and Engineering The Chinese University of Hong Kong
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Lecture 161 Lets examine a SPIM program in detail. io.asm This program is a simple routine which demonstrates input/output using assembly code. SPIM.
Assembly 03. Outline inc, dec movsx jmp, jnz Assembly Code Sections Labels String Variables equ $ Token 1.
MIPS assembly syntax Home Assignment 3 Assigned. Deadline 2016 February 14, Sunday.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
CS501 Advanced Computer Architecture Lecture 29 Dr.Noor Muhammad Sheikh.
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
Practical Session 3.
Chapter Topics The Basics of a C++ Program Data Types
Format of Assembly language
Assembly Lab 3.
CSC201: Computer Programming
Introduction to the C Language
Computer Architecture and Assembly Language
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Additional Assembly Programming Concepts
MIPS assembly syntax Comments
Microprocessor and Assembly Language
INTRODUCTION ABOUT ASSEMBLY
L7 – Assembler Directives
Defining Types of data expression Dn [name] expression Dn [name]
Basic Elements of C++ Chapter 2.
Computer Architecture and Assembly Language
Introduction to the C Language
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Ken D. Nguyen Department of Computer Science Georgia State University
Assembly Language Programming I: Introduction
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
A Simple Two-Pass Assembler
INTRODUCTION ABOUT ASSEMBLY
COMS 361 Computer Organization
Chapter 2 - Introduction to C Programming
Assembler Directives end label end of program, label is entry point
Computer Architecture and System Programming Laboratory
Some Assembly (Part 2) set.html.
Ken D. Nguyen Department of Computer Science Georgia State University
Introduction to C Programming
Chapter 1 c++ structure C++ Input / Output
Computer Organization and Assembly Language
Computer Architecture and Assembly Language
Introduction to 8086 Assembly Language
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Chapter 2 part #1 C++ Program Structure
Computer Architecture and System Programming Laboratory
Presentation transcript:

Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville

Assembly files (.asm)  We will be using the nasm assembler  Program Components  Comments  Labels  Directives  Data  Main subroutine, which is a global one  Instructions: generally the format of an NASM instruction is as follows Label Instruction Operands ; Comment

Program Organization : Skeleton file ; file: skel.asm ; This file is a skeleton that can be used to start assembly programs. %include "asm_io.inc" segment.data ; initialized data is put in the data segment here segment.bss ; uninitialized data is put in the bss segment segment.text global asm_main asm_main: enter 0,0 ; setup routine pusha ; code is put in the text segment. Do not modify the code before ; or after this comment. popa mov eax, 0 ; return back to C leave ret

Assembly I/O Routines  %include “asm_io.inc”  print_int prints out to the screen the value of the integer stored in EAX  print_char prints out to the screen the character whose ASCII value stored in AL  print_string prints out to the screen the contents of the string at the address stored in EAX. The string must be a Ctype string (i.e. null terminated)  print_nl prints out to the screen a new line character  read_int reads an integer from the keyboard and stores it into the EAX register  read_char reads a single character from the keyboard and stores its ASCII code into the EAX register  Uses a CALL instruction to invoke above routines

Comments  Comments are denoted by semi-colons (;).  Everything from the semi-colon to the end of the line is ignored.

Labels  Labels identify  The start of subroutines or locations to jump to in your code  Variables are declared as labels pointing to specific memory locations  Labels are local to your file/module unless you direct otherwise  The colon identifies a label (an address!)  Example: NewLabel:  To define a label as global we say globalNewLabel

Directives  Direct the assembler to do something  Define constants  Define memory to store data into  Group memory into segments  Conditionally include source code  Include other files

Equ and % define directives  The equ directive  Used to define named constants used in your assembly program  Syntax: symbol equ value  Similar to C’s const directive :(const int symbol = value)  The %define directive  Similar to C’s #define directive ( #define name value)  Most commonly used to define constant macros: %define SIZE 100 moveax, SIZE  Macros can be redefined, and can be more complex than simple constants

Data directives  Used in data segments to define room for memory  There are two ways memory can be reserved  Defines room for data without initial value ( segment.bss) Using : RESX directive  Defines room for data with initial value (segment.data) Using : DX directive  Note: X is replaced with a letter that determines the size of the object as following

Example: Data Directives L1db0;byte labeled L1 w/ initial value 0 decimal L2dw1000;word labeled L2 w/ initial value 1000 decimal L3db110101b;byte labeled L3 w/ initial value binary( 53) L4db12h;byte labeled L4 w/ initial value 12 hex (18 decimal) L5 db17o;byte labeled L5 w/ initial value 17 octal (15 decimal) L6dd1A92h;doubleword labeled L6 initialized to hex 1A92 L7resb1;1 uninitialized byte L8db“A”;byte initialized to ASCII of A = 65 L9 resw 100 ; reserves room for 100 words  Note: Double quotes and single quotes are treated the same

More examples  Sequences of memory may also be defined. L10 db 0, 1, 2, 3 ; defines 4 bytes L11 db "w", "o", "r", ’d’, 0 ; defines a C string = "word" L12 db ’word’, 0 ; same as L11  For large sequences, NASM’s TIMES directive is often useful. L13 times 100 db 0 ; equivalent to 100 (db 0)’s

Assembling the code  Use PuTTy and WinSCP application to use nasm commands  To edit your assembly file nano myfile.asm (or vi or emacs or joe or WinSCP editor )  To assemble your program nasm –f elf myfile.asm  To create an executable program gcc –m32 myfile.o driver.c asm_io.o  From the above command, you will get a new prompt and a file a.out or a.exe will be created  To run the program, give the command./a.out or./a.exe

Program Organization for CS3230  Generally, we will be using a C driver program called driver.c to run our assembler routines  Why driver.c ? 1. lets the C system set up the program to run correctly 2. All the segments and their corresponding segment registers will be initialized by C 3. The C library will also be available to be used by the assembly code