Discussion on mp1.

Slides:



Advertisements
Similar presentations
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Advertisements

Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
1 Computer Architecture MIPS Simulator and Assembly language.
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
1 Homework Reading Assignment –Professional Assembly Language, pp 39-59, MP1 –Get assignment file from my web page and study it –Make and populate.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
C and Data Structures Baojian Hua
Chapter 11-12, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Homework Reading Programming Assignments
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Topic 2d High-Level languages and Systems Software
SAPC Hardware Pentium CPU (or 486) 4M usable memory no hard disk; boot from floppy no keyboard or monitor or mouse COM2 serial port: used for console i/o.
1 Homework Reading –PAL pp , Continue mp1 –Questions? Continue lab sessions with your section.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Agenda Attack Lab C Exercises C Conventions C Debugging
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Object Oriented Software Development 4. C# data types, objects and references.
Announcements There is a Quiz today. There were problems with grading assignment 2, but they should be worked out today The web page for correcting the.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
1 Homework Continue with K&R Chapter 5 –Skipping sections for now –Not covering section 5.12 Continue on HW5.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
C++ Functions A bit of review (things we’ve covered so far)
Discussions on hw1 Objectives –Modify I/O library for serial ports –change from ring buffer to queue –implement interrupts I/O Library TTY0TTYn testio.
Lecture 3 Translation.
Homework Reading Machine Projects
Buffer Overflow Walk-Through
Last week: We talked about: History of C Compiler for C programming
Homework Reading Assignment Lab 1 MP1
Introduction to Operating Systems
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Computer Architecture & Operations I
Homework Reading PAL pp ,
Homework Reading Assignment Lab 1 Get ready for mp1
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Names and Attributes Names are a key programming language feature
A bit of C programming Lecture 3 Uli Raich.
Command line arguments
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Objectives Identify the built-in data types in C++
Homework Reading Machine Projects Labs PAL, pp ,
Additional Assembly Programming Concepts
CSE 303 Concepts and Tools for Software Development
Introduction to C Topics Compilation Using the gcc Compiler
Software Development with uMPS
Checking Memory Management
Introduction to C Topics Compilation Using the gcc Compiler
C Basics.
Buffer Overflow Walk-Through
Introduction to Operating Systems
Announcements Homework #7 due Monday at 3:00pm
Assembly Language Programming I: Introduction
SAPC Hardware Pentium CPU (or 486) 4M usable memory
Discussions on hw1 Objectives Modify I/O library for serial ports
More About Data Types & Functions
Memory Allocation CS 217.
Format String.
Govt. Polytechnic,Dhangar
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Homework Reading Programming Assignments Finish K&R Chapter 1
Appendix F C Programming Environment on UNIX Systems
Lab 4: Introduction to Scripting
Chapter 9: Pointers and String
Software Development Environment, File Storage & Compiling
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
IS 135 Business Programming
Introduction to SPIM Simulator
Return-to-libc Attacks
Introduction to C CS 3410.
Presentation transcript:

Discussion on mp1

Homework mp1 Get assignment file from my web page and study it Make and populate your UNIX mp1 subdirectory Study the source code for mp1

Analysis of the test Program For UNIX or SAPCs, basic process to develop programs is the same - only different in the details “Cross-compilation” is defined as the compilation of a program on one computer (Sun development host) for execution on another computer (SAPC target machine) We used gcc to generate an executable file that will run on the Sun-based UNIX system We used i386-gcc to generate an executable file that would NOT run on UNIX but will run on an SAPC

Analysis of the test Program(cont’d) Portability Defined as ability to write source code so that it can run on two or more types of machines Requires use of a different compiler/loader and library for each type of machine Notice that the library functions called by the test program worked slightly differently on the two types of machines (as noted in the text produced by the test program)

Analysis of the test Program (cont’d) Another difference between the Unix system and the SAPC is the presence/ absence of an operating system UNIX is an operating system that runs programs in a protected environment. Our code can not do some things such as access hardware directly Tutor is a debug monitor only and does not run programs in a protected environment. Our code can access hardware directly as you’ll see later

Machine Project 1 In mp1, you will add commands to a program that is a simple version of the Tutor program that we just used on the SAPC The program is “portable” so that it can be run on both the UNIX system and an SAPC You will learn about some things about the differences between the UNIX environment and the SAPC environment

Two Different Environments How is our program loaded into memory? UNIX SAPC 0x00000000 0x00000000 Reserved Reserved 0x00010000 Code 0x00020000 Data 0x00050000 Tutor 0x000A0000 Video Memory Reserved 0x000F0000 BIOS (ROM) 0x00100000 code data stack 0x003FFFFF Not Implemented Stack 0xFFFFFFFF 0xFFFFFFFF

Review of C Data Types Watch out for garbage pointers created using: typedef struct rect { int x1, y1, x2, y2; } Rectangle; Rectangle *recp; recp->x1 = 10; What is wrong with the above code? Answer: no memory pointed to by recp recp->x1 causes segmentation violation on UNIX, but writes into a random location in SAPC

malloc() in SAPC malloc() not supported in SAPC just define the variable Rectangle rect; rect.x1 = 10; Similarly, we can set up typedef struct view{ Rectangle first, last; } View; View v; v.first.x1 = 10; v.first = rect;

struct Cmd{…} Declaration Key to understanding “tutor” is the struct Cmd: typedef struct { char *cmdtoken; /* char string to invoke Cmd */ int (*cmdfn)(); /* function to call for this Cmd */ char *help; /* helpstring for Cmd */ } Cmd; Cmd *cmdtoken ‘m’ ‘d’ ‘\0’ (*cmdfn) ( ) Function to process command *help ‘h’ ‘e’ ‘l’ ‘p’ ‘ ’ ‘t’ ‘e’ ‘x’ ‘t’ ‘\0’

struct Cmd{…} Instantiation Cmd cmds[] = { {"md", mem_display, "Memory display: MD <addr>"}, {"ms", mem_set, "Memory set: MS <addr> <value>"}, {"h", help, "Help: H <command>"}, {"s", stop, "Stop" }, {NULL, NULL, NULL}}; Cmd * cp= cmds; /* or &cmds */ what is cp->cmdtoken? what is cp->cmdfn? what is cp->help? cp++; /* where is cp? */ what is cp->cmdtoken? cp->cmdfn? cp_->help?

Machine Project 1 Your job entails Replacing the stub for the md command to: Convert the character string to an integer Use that integer as an address (a pointer to memory) Find the contents of that address Display the contents of that address to the terminal Adding commands to the command table and writing code to make both of them work Memory Set - ms Help - h

makefile Go over the makefile in mp1 How to make the UNIX version? % make tutor # creates tutor executable on UNIX # and usyms symbol table How to make the SAPC version? % make tutor.lnx # creates tutor executable on SAPC # and syms symbol table

What Needs to be Done tutor.c It has the main() Get cmd token from user by parsing : getcmd() The actual parsing is done by slex() No need to modify tutor.c in mp1

What Needs to be Done (cont’d) cmds.c Need to modify the Cmd struct to include: “ms” and “h” Add code in mem_display(), help(), mem_set() functions Command routine calls with 2 arguments, e.g. mem_display(Cmd *cp, char *arguments) If we enter a command “md 10000” to display the contents of 16 locations starting with 10000, the arguments passed are: Address of the string “10000” &cmds[0]