All code must be commented! Each problem part (1,2,3a,3b,…) will be in a separate file: problem_1.s …. You may be asked to demonstrate your program. You.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
SPIM and MIPS programming
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Assembly Language Programming
Ch. 8 Functions.
1 Computer Architecture MIPS Simulator and Assembly language.
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
ECE 0142 Recitation #5.
Functions Functions and Parameters. History A function call needs to save the registers in use The called function will use the registers The registers.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
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,
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
1 - buttons Click “Step Forward” to execute one line of the program. Click “Reset” to start over. “Play,” “Stop,” and “Step Back” are disabled in this.
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 ;
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Website Development with PHP and MySQL Saving Data.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
CWRU EECS 322 March 8, 2000 The SPIM simulator EECS 322: Computer Architecture.
APS105 Strings. C String storage We have used strings in printf format strings –Ex: printf(“Hello world\n”); “Hello world\n” is a string (of characters)
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
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.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Instructor: Francis G. Wolff Case Western Reserve University This presentation uses powerpoint animation: please viewshow EECS 322.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Strings Chapter 5.
Erik Jonsson School of Engineering and Computer Science FEARLESS Engineeringwww.utdallas.edu/~pervin EE/CE 2310 – HON/002 Introduction to Digital Systems.
The SPIM Trap Handler Syscall Trap handler services String operations File operations Memory allocation Central Connecticut State University, MIPS Tutorial.
Characters and Strings
Integers/Characters Input/Output Integers and Characters Input/Output System Calls. syscall Trap Handler Services for Integers and Characters Read Integer,
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
C is a high level language (HLL)
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
File I/O. I/O Flags Flags are passed to give some information about how the file is to be used. – Read only file – flag=0x0 – Write only file – flag=0x1.
5.13 Recursion Recursive functions Functions that call themselves
Computer Science 210 Computer Organization
A bit of C programming Lecture 3 Uli Raich.
Integers/Characters Input/Output
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Ken D. Nguyen Department of Computer Science Georgia State University
توابع ورودي-خروجي.
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Passing Parameters Data passed to a subroutine is called a parameter.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Chapter 7 Assembly Language
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Homework Reading Programming Assignments Finish K&R Chapter 1
Functions continued.
Arrays.
Introduction to C EECS May 2019.
Some Assembly (Part 2) set.html.
Ken D. Nguyen Department of Computer Science Georgia State University
CS1100 Computational Engineering
EECE.2160 ECE Application Programming
Introduction to SPIM Simulator
Format String Vulnerability
Presentation transcript:

All code must be commented! Each problem part (1,2,3a,3b,…) will be in a separate file: problem_1.s …. You may be asked to demonstrate your program. You must turn in floppy and printouts. 1. (10%) Problem A.7 on page A-77 in textbook 2. (20%) Problem A.8 on page A-77 in textbook 3a. (10%) Modify the mapped_io.s program to echo (tx) each rx character back as is typed. Read A-36 to A-38 EECS 322: SPIM assignment / project

Note: functions return values via $v0 if function uses $s0 to $s7 it must be saved on the stack. (see page 134 and page A-22) 3b. (10%) Improve the mapped_io.s by writing your own ANSI C Language function: char *gets(char *s) where char *s is a pointer to a pre-allocated string of bytes. Gets returns the original pointer *s passed in. Gets inputs each character and echos it until a newline is encountered (0x0a). The newline is not saved in the final string. The returned string is null terminated. EECS 322: SPIM assignment / project

3c. (10%) Improve the mapped_io.s by writing your own ANSI C Language function: int puts(char *s) where char *s is a pointer to a string of bytes to be printed. Puts prints each character until a null is encountered (0x0a) in the string. A newline is then also printed to the console. Puts returns the number of characters written to the console. EECS 322: SPIM assignment / project

3d. (10%) Write your own ANSI C Language function: int atoi(char *s) where char *s is a pointer to a null terminated string of bytes of decimal ascii digits. atoi returns the integer (I.e. convert to binary) of the input string. 3e. (10%) Write tour own C Language function: void itoa(char *s, int n); where int n is a binary integer char *s is a pointer to a null terminated string of bytes of decimal ascii digits converted from n. EECS 322: SPIM assignment / project

3f. (20%) Rewrite problem 1 using your own subroutines. No system calls allowed. Also hand in the C language version of your program. You do not need to run the C code. EECS 322: SPIM assignment / project char *gets(char *s) reads until newline, newline discarded, and returns a string terminated with a zero. int puts(char * s) prints a string followed by newline and returns the number of characters written. int atoi(char *s) converts a ascii string to binary number void itoa(char *s, int n) returns a string converted from n

EECS 322: SPIM assignment / project #Goto to dos prompt and type: pcspim -mapped_io #Warning bugs have been inserted!.globl main main:#main has to be a global label addu$s7, $0, $ra#save the return address in a global register #Output the string "Hello World" on separate line.data #.globlhello hello:.asciiz "\nHello World\n"#string to print goodbye:.asciiz "\nGoodbye\n" rx_buffer:.asciiz "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" rx_cntl:.word0xffff0000 tx_cntl:.word0xffff0008.text li$v0, 4#print_str (system call 4) la$a0, hello# takes the address of string as an argument syscall la$a0, rx_buffer rx_wait: lw$t1,rx_cntl rx_wait1: lw$t2,0($t1)# ready? andi$t2,$t2,1 beq$t2,$0,rx_wait1#no - loop lw$t2,4($t1)#yes - get character sb$t2,0($a0)#..store it addi$t2,$t2,-10#end of line? beq$t2,$0,rx_wait2#yes - make it zero addi$a0,$a0,2#increment string address jrx_wait1

EECS 322: SPIM assignment / project rx_wait2: sb$0,0($a0)#store zero la$a0, rx_buffer tx_wait: lw$t1,tx_cntl tx_wait1: lw$t2,0($t1) andi$t2,$t2,1 beq$t2,$0,tx_wait1 lbu$t2,0($a0) beq$t2,$0,tx_wait2 sw$t2,4($t1) addi$a0,$a0,1#increment string address jtx_wait1 tx_wait2: #Usual stuff at the end of the main addu$ra, $0, $s7#restore the return address jr$ra#return to the main program add$0, $0, $0#nop