Summer 2003 Lecture 14 07/02/03

Similar documents
Summer 2003 Lecture 15 07/03/03

Assembler Programming. Lecture 10

Segmentation in Assembly Language Programming

Parameter Passing. Procedure line. Calling procedure line. Most subroutines require parameters Can sometimes pass parameters via registers

PHY4635/5635 Spring Lecture 8: Program Control Instructions

Objectives. ICT106 Fundamentals of Computer Systems Topic 8. Procedures, Calling and Exit conventions, Run-time Stack Ref: Irvine, Ch 5 & 8

Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine

Summer 2003 Lecture 4 06/14/03

Dr. D.M. Akbar Hussain

Chapter 7 Subroutines. Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C

CS401 - Computer Architecture and Assembly Language Programming Glossary By

Summary: Direct Code Generation

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

Mating Assembly with C

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Computer Architecture and System Software Lecture 07: Assembly Language Programming

ECE251: Tuesday September 11

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

1: /********************************************************** 2: * A

ECE251: Tuesday September 12

Object Code (Machine Code) Dr. D. M. Akbar Hussain Department of Software Engineering & Media Technology. Three Address Code

Computer Architecture and System Software Lecture 06: Assembly Language Programming

System Software Assignment 1 Runtime Support for Procedures

Implementing Subroutines. Outline [1]

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

ORG ; TWO. Assembly Language Programming

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

Today's Topics. CISC 458 Winter J.R. Cordy

Overview of Compiler. A. Introduction

Summer 2003 Lecture 12 06/26/03

Computer Systems Lecture 9

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

PESIT Bangalore South Campus

Chapter 9 :: Subroutines and Control Abstraction

SOURCE LANGUAGE DESCRIPTION

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

CIT Week13 Lecture

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

Xuan Guo. Lecture XIX: Subroutines (2) CSC 3210 Computer Organization and Programming Georgia State University. March 31, 2015.

The Stack. Lecture 15: The Stack. The Stack. Adding Elements. What is it? What is it used for?

Wednesday, October 15, 14. Functions

CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers. MC

UNIT 4. Modular Programming

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

x86 architecture et similia

Lecture 3: C Programm

8086 Interrupts and Interrupt Responses:

SISTEMI EMBEDDED. Stack, Subroutine, Parameter Passing C Storage Classes and Scope. Federico Baronti Last version:

G Programming Languages - Fall 2012

3: 4: 5: 9: ',0 10: ',0 11: ',0 12: 13:.CODE 14: INCLUDE

Experiment 8 8 Subroutine Handling Instructions and Macros

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

EE 361 University of Hawaii Fall

Practical Malware Analysis

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

Topics Introduction to Microprocessors. Chapter 5 Macros and modules. What is macro? How to use macro? (I) How to use macro?

Memory and Pointers written by Cathy Saxton

EE475 Lab #3 Fall Memory Placement and Interrupts

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS-201 Introduction to Programming with Java

Assembly Language for Intel-Based Computers, 4 th Edition. Lecture 25: Interface With High-Level Language

W4118: PC Hardware and x86. Junfeng Yang

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Contents. 8-1 Copyright (c) N. Afshartous

Compiling Techniques

Program Exploitation Intro

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

System calls and assembler

Functions in C. Lecture Topics. Lecture materials. Homework. Machine problem. Announcements. ECE 190 Lecture 16 March 9, 2011

Assignment no:4 on chapter no :3 : Instruction set of 8086

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

x86 assembly CS449 Fall 2017

Control Abstraction. Hwansoo Han

Concepts Introduced in Chapter 7

Program SoC using C Language


CA Compiler Construction

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Run-time Environments

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

Run-time Environments

Lesson 4. Stack, Procedures and Macros

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Module 3 Instruction Set Architecture (ISA)

Pointers II. Class 31

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

EE 314 Spring 2003 Microprocessor Systems

CG2007 Microprocessor systems.

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

1 Lexical Considerations

We will begin our study of computer architecture From this perspective. Machine Language Control Unit

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:

LABORATORY WORK NO. 8 WORKING WITH MACROS AND LIBRARIES

ELEC 242 Time Delay Procedure

Engineer To Engineer Note

Technical Questions. Q 1) What are the key features in C programming language?

Procedures and the Stack. Chapter 4 S. Dandamudi

Assembly Language Programming

Transcription:

Summer 2003 Lecture 14 07/02/03 LAB 6 Lab 6 involves interfacing to the IBM PC parallel port Use the material on wwwbeyondlogicorg for reference This lab requires the use of a Digilab board Everyone should have one, but at least each group working together needs to have a board Parallel Port Registers Address: Base + 0 => Data Port Base + 1 => Status Port Base + 2 => Control Port Status port bits: Signal Name Pin # Inverted Bit 7 Busy 11 Yes Bit 6 Ack 10 Bit 5 Paper Out 12 Bit 4 Select In 13 Bit 3 Error 15 Bit 2 IRQ N/A Bit 1 Reserved Bit 0 Reserved

Control Port Bits Signal Name Pin # Inverted Bit 7 Unused Bit 6 Unused Bit 5 Enable bi-directional port N/A Bit 4 Enable IRQ via ACK line N/A Bit 3 Select Printer 17 Yes Bit 2 Initialize Printer (Reset) 16 No Bit 1 Auto Linefeed 14 Yes Bit 0 Strobe 1 Yes Digilab Board Initialization: A program will be provided on the lab machines that is used to initialize the Digilab boards It is called cfglab6exe, and will be placed in a directory on the path, so that it can be executed simply by typing its name anywhere from a DOS prompt C Programming Language Semantics Parameter passing to procedures: C is call by value for scalar variables, call by reference for vector variables Call by value means that the value of the parameter is pushed onto the stack and passed to the procedure as the parameter Call by reference means that the address of the parameter is pushed onto the stack When a variable is passed by value, the called procedure can t modify the value of the parameter in the caller s context When a variable is passed by reference, then the called procedure has a pointer to the actual variable and not a copy of its value In this case, the called procedure can modify the value of the caller s variable (In some languages, such as FORTRAN, which are call by reference for scalar variables, it is possible to modify the value of constants) Variable Initialization:

In C, when a variable is declared, it is possible to give it an initial value by specifying an initializer When the variable has static storage class (either by using the static keyword when declaring a local variable, or by declaring it outside of a procedure) the initialization is done statically by the compiler when the program is compiled, and no runtime code is required to perform the initialization However, when an automatic variable, in a procedure, is initialized, it is necessary for the compiler to generate code to perform the initialization Initialization of automatic variables in a procedure must be performed each time the procedure is entered, before any other code in the procedure is executed In-Line Assembler: Most C compilers support some form of in-line assembler This is a nonstandard extension to the C language, therefore, the syntax varies from one vendor s assembler to the next Also, any in-line assembler code is non-portable between processors and sometimes between operating systems on the same processor With the Borland C++ compiler used in our lab, the syntax is: _asm opcode operands or: _asm { opcode opcode operands operands The first syntax allows a single assembly language statement to be entered The second syntax allows a block of assembly language statements to be entered Please note: With the Borland compiler, the opening brace ({) must be on the same line as the _asm keyword If the brace isn t on the same line, the compiler won t recognize it as an entry into in-line assembly mode and will report numerous syntax errors on the assembly language statements

The Borland compiler also does not allow the definition of statement labels within the in-line assembly code If you need to create a label for the target of a jump in assembler, you need to close the in-line assembly block, create the label using the C syntax for labels, and then enter a new in-line assembly block _asm { cmp ax,bx jnz foo xchg ax,bx foo: _asm { mov dx,ax ;asm code ;jump to other asm code //C statementlabel ;other asm code Initialization of Variables In the C (or C++) programming language any variable definition can have an optional initializer for the variable How and when the initialization occurs is determined by the storage class of the variable The syntax is similar to the following: int foo = 10; The term storage class refers to how and when memory space (storage) for the variable is allocated In C there are basically two options for storage class: static and automatic The memory for static variables is allocated by the compiler at the time of compilation In an x86 system, the compiler will reserve space in the program s data segment at compilation time to store the variable The memory space for automatic variables is allocated at run time on the stack The compiler will generate code to allocate space for automatic local variables on entry to a procedure and de-allocate the space on exit from the procedure

The storage class assigned to a variable is determined by how and where the variable is defined All variables defined outside the scope of any procedure (ie outside the body of any subroutine or function) must be static Thus, global variables are, and must be static By default, variables defined within a procedure (local variables) will be of storage class automatic It is possible to specify that a local variable within a procedure be given static storage class by using the keyword static at the beginning of the declaration, as follows: static int foo = 10;

The assignment of initial values is determined by the variable s storage class All static variables will be initialized once before execution of the program begins Generally, this is done by the compiler initializing the memory allocated in the data segment for all initialized variables Most C compilers for the x86 processors actually generate two data segments one for initialized variables and one for uninitialized variables, which will be combined by the linker into a single segment Automatic variables are initialized each time that the procedure where they are declared is executed Because the memory is allocated on the stack automatically on entry to the procedure, the initialization must also be performed on each entry to the procedure

For scalar variables, the initialization could look something like this: C Code: void subr(void) { int x = 1; int y = 2; x = x+y; return x ASM Code subr proc near push bp mov bp,sp sub sp,4 mov [bp-2],1 ;initialize x mov [bp-4],2 ;initialize y mov ax,[bp-2] add ax,[bp-4] mov sp,bp pop bp ret subr endp Notice that the compiler would generate code to perform the initialization that would explicitly assign a constant value to the variable This is essentially the same code that would be generated by an assignment statement In C, initializing a scalar variable via an initializer on the declaration and via an explicit assignment statement cause the compiler to generate essentially the same code