Study Guide for Midterm - Machine Dependent Programming | ECS 050, Study notes of Computer Science

Material Type: Notes; Class: Machine Dependent Prog; Subject: Engineering Computer Science; University: University of California - Davis; Term: Winter 2008;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-xvz
koofers-user-xvz 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Discussion #2 Notes
01/28/08
Practice Midterm Problem #1 Write the CUSP floating point representation for the decimal 135.0625.
Remember the CUSP’s representation is 8-bit exponent, followed by the sign bit, followed by the 16-bit
mantissa which excludes the leading 1 (leading one is implicit). Thus, as 13510 = 100001112.062510 =
.00012. The binary representation of 135.0625 is 10000111.0001 = 1.000011100010000 27
8-bit exponent field = 7 = 135excess128 = 100001112Sign bit = 0, positive number 16 bit mantissa field with
implicit leading 1 = 000011100010000
Putting all that together you get: 100001110000011100010000 which is 870710.
Practice Midterm Problem #2 Signed (2scomplement) values are added or substracted in exactly the
same manner as unsigned ones. Remember, as mentioned in the book, that computers do not substract
they negate the second operand and add them together. Also, in the case of unsigned addition, overflow
occurs when the correct sum is too large to be represented using the available bits. In the case of unsigned
substraction, overflow occurs if the value being substracted is the larger one. In the case of signed addition
as well as substraction, overflow occurs when the result has an incorrect sign.
Assume signed, 2scomplement operation.
A56FF3
+ 9FF7FF
OV 456782
381734
- 808080
B796B4
A689BE
- B8FDE3
A689BE
+ 47021D
ED8BDB
Exercise #1
1. What is the purpose of mini os.lst and mini os.obj files?
2. Say that you are writing a program and that it currenty contains a bug. How would you go about
debugging it?
1
pf3

Partial preview of the text

Download Study Guide for Midterm - Machine Dependent Programming | ECS 050 and more Study notes Computer Science in PDF only on Docsity!

Discussion #2 Notes

Practice Midterm Problem #1 Write the CUSP floating point representation for the decimal 135.0625.

Remember the CUSP’s representation is 8-bit exponent, followed by the sign bit, followed by the 16-bit mantissa which excludes the leading 1 (leading one is implicit). Thus, as 13510 = 10000111 2. 062510 =

. 00012. The binary representation of 135. 0625 is 10000111 .0001 = 1. 000011100010000 ∗ 27

8-bit exponent field = 7 = 135excess 128 = 10000111 2 Sign bit = 0 , positive number 16 bit mantissa field with implicit leading 1 = 000011100010000

Putting all that together you get: 100001110000011100010000 which is 870710.

Practice Midterm Problem #2 Signed ( 2 s^ complement) values are added or substracted in exactly the same manner as unsigned ones. Remember, as mentioned in the book, that computers do not substract – they negate the second operand and add them together. Also, in the case of unsigned addition, overflow occurs when the correct sum is too large to be represented using the available bits. In the case of unsigned substraction, overflow occurs if the value being substracted is the larger one. In the case of signed addition as well as substraction, overflow occurs when the result has an incorrect sign.

Assume signed, 2 s^ complement operation.

A56FF

  • 9FF7FF OV 456782

B796B

A689BE

- B8FDE

A689BE

+ 47021D

ED8BDB

Exercise #

  1. What is the purpose of mini os.lst and mini os.obj files?
  2. Say that you are writing a program and that it currenty contains a bug. How would you go about debugging it?
  1. How do you run a program in cusp?
  2. How do you step through a program?
  3. Why is the first instruction of all your programs LDS# $E00?
  4. What does the instruction JMP FUNCTION accomplish?
  5. What does the instruction RTN accomplish?
  6. What is the purpose of mini os library? What are some functions that it provides?

Exercise #2 Convert the following C code into CUSP.

if (n <= 10) x = 1; else { x = 3; y = 5; }

In CUSP code.

LDA N ; n <= 10? CMA# 10 JGT ELSE ; If not, skip to else part LDA# 1 ; x = 1 STA X JMP AFTER ; Branch around else part ELSE: LDA# 3 ; x = 3 STA X LDA# 5 ; y = 5 STA Y AFTER: ... ; Both paths continue from here

More C code.

i = 1; while (i <= 10) { ... i++; }

In CUSP code.

LDA# 1 ; i = 1 STA I LOOP: CMA# 10 ; i <= 10? JGT OUT ; if not, break ... INC I ; i++ JMP LOOP ; go re-test i OUT: ...