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.
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Lab6 – Debug Assembly Language Lab
Outline Learning Assembly by an Example.  Program Formats  Some Simple Instructions  Assemble and Execute Learning Another Example  Data Definition.
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.
Assembly Language for Intel-Based Computers Chapter 3: Assembly Language Fundamentals Kip Irvine.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
8051 ASSEMBLY LANGUAGE PROGRAMMING
CS2422 Assembly Language & System Programming September 26, 2006.
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.
Homework Reading Programming Assignments
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 ;
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
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.
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
Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 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.
X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)
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:
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
NASM ASSEMBLER & COMPILE WITH GCC 어셈러브 refered to ‘PC Assembly Language’ by Paul A. Carter
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Practical Session 3.
Lecture 3 Translation.
Format of Assembly language
Assembly Lab 3.
Computer Architecture and Assembly Language
Debugging with gdb gdb is the GNU debugger on our CS machines.
Additional Assembly Programming Concepts
MIPS assembly syntax Comments
Microprocessor and Assembly Language
Computer Architecture and Assembly Language
Ken D. Nguyen Department of Computer Science Georgia State University
Assembly Language Programming I: Introduction
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
INTRODUCTION ABOUT ASSEMBLY
Assembler Directives end label end of program, label is entry point
Computer Architecture and System Programming Laboratory
Ken D. Nguyen Department of Computer Science Georgia State University
Introduction to C Programming
Computer Organization and Assembly Language
Computer Architecture and Assembly Language
Introduction to 8086 Assembly Language
Computer Architecture and System Programming Laboratory
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
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 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

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

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

Debugging  There are four debugging routines named:  dump_regs: this macro prints out the values of the registers (in hexadecimal) Syntax : dump_regs X X: It takes a single integer argument that is printed out as well. This can be used to distinguish the output of different dump regs commands  dump_mem: this macro prints out the values of a region of memory (in hexadecimal) and also as ASCII characters Syntax: dump_mem X, label, Y X: This can be used to distinguish the output of different dump_mem commands Label: the starting address of displayed region Y: the number of 16-byte paragraphs to display after the starting address

Debugging (cont.)  There are four debugging routines named:  dump_stack: this macro prints out the values on the CPU stack Syntax: dump_stack X, Y, Z X: This can be used to distinguish the output of different dump_stack commands Y: the number of double words to display below the address that the EBP register holds Z: the number of double words to display above the address in EBP  dump_math: this macro prints out the values of the registers of the math coprocessor Syntax: dump_math X X: This can be used to distinguish the output of different dump_math commands

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