Discussion of Assignment 9 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.

Slides:



Advertisements
Similar presentations
The “Little Man Computer” Version
Advertisements

CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
PART 6 Programming 1.Decomposition 2.Three Constructs 3.Counting Example 4.Debugging.
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Variables Conditionals Loops The concept of Iteration Two types of loops: While For When do we use them? Iteration in the context of computer graphics.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
The Little man computer
Recursion. Recursion is a powerful technique for thinking about a process It can be used to simulate a loop, or for many other kinds of applications In.
Recursion in Python. Recursion Problems in every area of life can be defined recursively, that is, they can be described in terms of themselves. An English.
Lab6 – Debug Assembly Language Lab
Recursion.
Introduction to a Programming Environment
Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original.
CODING Research Data Management. Research Data Management Coding When writing software or analytical code it is important that others and your future.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
MIPS I/O and Interrupt. SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3 rd Edition) and B7-B8 (4 th Edition).
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
1 CS/COE0447 Computer Organization & Assembly Language Pre-Chapter 2.
Methods (Functions) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
1 A Simple but Realistic Assembly Language for a Course in Computer Organization Eric Larson Moon Ok Kim Seattle University October 25, 2008.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
Chapter 4 - Implementing Standard Program Structures in 8086 Assembly Language from Microprocessors and Interfacing by Douglas Hall.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
CS 320 Assignment 1 Rewriting the MISC Osystem class to support loading machine language programs at addresses other than 0 1.
Debugging Strategies from Software Carpentry. Agan's Rules Many people make debugging harder than it needs to be by: Using inadequate tools Not going.
Diagnostic Pathfinder for Instructors. Diagnostic Pathfinder Local File vs. Database Normal operations Expert operations Admin operations.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Understanding the TigerSHARC ALU pipeline Determining the speed of one stage of IIR filter – Part 2 Understanding the pipeline.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Lecture 5 Page 1 CS 111 Online Processes CS 111 On-Line MS Program Operating Systems Peter Reiher.
Intermediate 2 Computing Unit 2 - Software Development Topic 2 - Software Development Languages and Environments.
1.4 Representation of data in computer systems Instructions.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
More on Pipelining 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Arrays and Strings in Assembly
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
More on Pipelining 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
Variables, Types, Operations on Numbers CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
6/27/20161 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Recursion CSE 2320 – Algorithms and Data Structures
The Little man computer
GCSE COMPUTER SCIENCE Computers 1.5 Assembly Language.
14 Compilers, Interpreters and Debuggers
ECE 3430 – Intro to Microcomputer Systems
Mechanism: Address Translation
© Craig Zilles (adapted from slides by Howard Huang)
A451 Theory – 7 Programming 7A, B - Algorithms.
Swapping Segmented paging allows us to have non-contiguous allocations
CS41B recursion David Kauchak CS 52 – Fall 2015.
How to Run a Java Program
Processor Fundamentals
How to Run a Java Program
Functions in Hmmm Assembly
Recursion Taken from notes by Dr. Neil Moore
Some Assembly (Part 2) set.html.
Mechanism: Address Translation
© Craig Zilles (adapted from slides by Howard Huang)
Software Development Techniques
Presentation transcript:

Discussion of Assignment 9 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington

Returning Versus Printing Regarding the programming tasks in assignment 9, many students have asked: "do we print/return decimal, ASCII, or hexadecimal numbers"? If you have this question, it means that you are making a fundamental mistake: you are confusing "returning a value" with "printing a value". There are multiple ways to answer/clarify this question. The simplest one, is to answer with another question: what do the given C functions do? – You are asked to implement specific C functions, so you have questions about what your code should be doing, just try to do exactly what the C functions do. 2

Returning Versus Printing Regarding the programming tasks in assignment 9, many students have asked: "do we print/return decimal, ASCII, or hexadecimal numbers"? What do the given C functions do? – The given C functions do not do any printing. – Thus, your functions should not do any printing. It is understandable (even recommended) that you may put some code to print stuff for debugging purposes. – I would actually recommend that you copy and paste the print_digit and print_number functions to each of your programs, so that you can call print_number for debugging. However, once your code is done, you should clean it up and remove, before you submit, any code that does printing. 3

Returning Versus Printing In general, you are asked to implement functions that compute and return something. Once you have computed this something, you should store it on register r0. – This is the convention we follow for "returning a value". ASCII codes are only used for printing. When you return a number, the ASCII code of that number is irrelevant. It is worth repeating, returning a value has nothing to do with printing a value. 4

Reading Assembly Code Assembly code is painful to read and understand. However, you are expected to read any assembly code that you are given. How to read assembly code? – Start at the beginning. – Start mentally executing instructions, one by one. – On a piece of paper, write the values of registers and memory addresses that you're using. – For each instruction that you "execute" in your mind, update those values on your piece of paper. 5

Reading Assembly Code If you ask me a question of the sort "I do not understand how this piece of code works", I will always ask you to show me how you manually execute this code line by line. Not understanding the code means that there is one specific line such that: – You do not understand that line. – You understand everything before that. If you ask me questions where you identify that line, I will be happy to tell you what that line does. If you ask me questions of the sort "what does this code do?" I will simply ask you to show me how you manually execute the code. – Most of the times, by the time you are done with this exercise, you have answered your own questions. 6

Existing Assembly Examples Look at assembly examples that are available on the slides and the course website. A lot of questions can be answered by just looking at those examples. For example, consider the factorial function. – How does it handle "returning" a value? – How does it handle recursive calls? Identifying available code that does things similar to what you need to do can save you a lot of time. 7

The GDB Debugger Using the debugger is also a great tool for: Understanding code. Debugging your own code. There are instructions on the course website on how to use the debugger. 8

Infinite Loops Some people have reported that their program gets into an infinite loop where it keeps rerunning from the beginning. I have verified that even correct code can get into this behavior. This phenomenon is somewhat complicated to explain, but it is easy to fix. 9

Infinite Loops First of all, how to fix: Short version: At the very end of your program (every program that you write), put these lines: the_end: b the_end These lines make sure that your program, when it reaches the end, stays there forever. 10

Infinite Loops Longer version: At the very end of your program (every program that you write), put the code on the right. This way, when you get to the end of the program, you see the word END printed, so you know that you reached the end of your program (as opposed to getting stuck in some infinite loop somewhere else). 11 ldr r4,=0x101f1000 mov r1, #13 str r1, [r4] mov r1, #10 str r1, [r4] mov r1, #'E' str r1, [r4] mov r1, #'N' str r1, [r4] mov r1, #'D' str r1, [r4] the_end: b the_end

Infinite Loops The assembly programs that we write run in a very primitive environment. How does a program know when to stop? What does the CPU execute when the program stops? 12

Infinite Loops The assembly programs that we write run in a very primitive environment. How does a program know when to stop? What does the CPU execute when the program stops? These are issues that are typically handled by an operating system. In our case, the the program runs on a simulated machine with no operating system. When the program finishes, what is the CPU supposed to do? 13

Infinite Loops When the program finishes, what is the CPU supposed to do? The CPU just fetches the next instruction from memory. What is the next instruction? It is just whatever happened to reside in memory at that time. Thus, while you think that your program has finished executing, the program still executes meaningless instructions. However, at some point, the program may reach memory that you have used on your stack. Some of the data you have stored on the stack, when interpreted as instructions, executes a branch to the beginning of the program. 14

Infinite Loops In summary: correct code getting into an infinite loop is a problem that you may or may have not run across. If you have not run across it,do not worry about it. If you have, it may take hours trying to find the mistake where there isn't one. Using the suggested fixes (especially the one that prints END at the end) resolves this issue. Plus, using the suggested fixes ensures that if you do observe an infinite loop, the problem is with your code. If you mess up your stack (by adding or subtracting the wrong values, or restoring the value of lr from the wrong place) you may get all sorts of weird execution behavior. 15