Number Systems and SPARC Assembly: Binary Addition, Bit Operations, and Local Variables, Exams of Computer Science

Various topics in number systems and sparc assembly programming. It includes exercises on binary addition, condition code bits, overflow detection, bit operations, and local variables. The document also provides sparc assembly code for c statements and conversions between different number systems.

Typology: Exams

Pre 2010

Uploaded on 03/28/2010

koofers-user-hd1-1
koofers-user-hd1-1 ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
cs30x_______
Name _________________________
Student ID ____________________ Signature_______________________
CSE 30
Spring 2006
Final Exam
1. Number Systems ___________________ (15 points)
2. Binary Addition/Condition Code Bits/Overflow Detection ___________________ (12 points)
3. Branching ___________________ (18 points)
4. Bit Operations ___________________ (13 points)
5. Recursion/SPARC Assembly ___________________ (10 points)
6. Local Variables, The Stack and Return Values ___________________ (27 points)
7. Bit Slinging ___________________ (12 points)
8. Floating Point ___________________ (12 points)
9. Machine Instructions ___________________ (20 points)
10. Linkage, Scope, Lifetime, Data ___________________ (34 points)
11. Load/Store/Memory ___________________ (9 points)
12. Miscellaneous ___________________ (33 points)
SubTotal ___________________ (215 points)
Extra Credit ___________________ (10 points)
Total ___________________
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Number Systems and SPARC Assembly: Binary Addition, Bit Operations, and Local Variables and more Exams Computer Science in PDF only on Docsity!

cs30x_______ Name _________________________

Student ID ____________________ Signature_______________________

CSE 30

Spring 2006

Final Exam

1. Number Systems ___________________ (15 points)

2. Binary Addition/Condition Code Bits/Overflow Detection ___________________ (12 points)

3. Branching ___________________ (18 points)

4. Bit Operations ___________________ (13 points)

5. Recursion/SPARC Assembly ___________________ (10 points)

6. Local Variables, The Stack and Return Values ___________________ (27 points)

7. Bit Slinging ___________________ (12 points)

8. Floating Point ___________________ (12 points)

9. Machine Instructions ___________________ (20 points)

10. Linkage, Scope, Lifetime, Data ___________________ (34 points)

11. Load/Store/Memory ___________________ (9 points)

12. Miscellaneous ___________________ (33 points)

SubTotal ___________________ (215 points)

Extra Credit ___________________ (10 points)

Total ___________________

1. Number Systems

Convert 0xFA5A (2โ€™s complement, 16-bit word) to the following. (6 points)

binary______________________________________ (straight bit pattern translation)

octal________________________________________(straight bit pattern translation)

decimal____________________________________ (pos/neg decimal value from 2's complement encoding)

Convert 37710 to the following (assume 16-bit word). Express answers in hexadecimal. (3 points)

sign-magnitude __________________________________

1โ€™s complement __________________________________

2โ€™s complement __________________________________

Convert -652 10 to the following (assume 16-bit word). Express answers in hexadecimal. (6 points)

sign-magnitude___________________________________

1โ€™s complement __________________________________

2โ€™s complement __________________________________

2. Binary Addition/Condition Code Bits/Overflow Detection

Indicate what the condition code bits are when adding the following 8-bit 2โ€™s complement numbers. (12 points)

N Z V C N Z V C N Z V C

4. Bit Operations

What is the value of %l0 after each statement is executed? Express your answers in hexadecimal.

set 0x2006ACED, %l

set 0x98675309, %l

or %l0, %l1, %l

Value in %l0 is _______________________________________ (2 points)

set 0x2006ACED, %l

sll %l0, 13, %l

Value in %l0 is _______________________________________ (2 points)

set 0x2006ACED, %l

srl %l0, 5, %l

Value in %l0 is _______________________________________ (2 points)

set 0x2006ACED, %l

set 0x????????, %l

xor %l0, %l1, %l0! Value in %l0 is now OxDEADBEEF

Value set in %l1 must be this bit pattern _______________________________________ (3 points)

set 0x2006ACED, %l

set 0x98675309, %l

and %l0, %l1, %l

Value in %l0 is _______________________________________ (2 points)

set 0x2006ACED, %l

sra %l0, 13, %l

Value in %l0 is _______________________________________ (2 points)

5. Recursion/SPARC Assembly

Given main.s and recurse.s, what gets printed when executed? (10 points)

.global main /* main.s */ .section ".rodata" .align 4 .word 0x code: .word 0x33736447, 0x72657074, 0x6B735061, 0x663D4E37, 0x2B20422B, 0x .word 0x662F7522, 0x43537300, 0x .section ".text" main: save %sp, -92 & -8, %sp set code, %o mov 27, %o call fubar nop ret restore


.global fubar /* fubar.s */ .section ".rodata" fmt: .asciz "%c"

.section ".text" fubar: save %sp, -(92 + 1) & -8, %sp cmp %i0, %g be end nop ldub [%i0 + %i1], %l cmp %l0, %g be end nop dec %l stb %l0, [%fp - 1] sub %i1, 3, %o mov %i0, %o call fubar nop set fmt, %o ldub [%fp - 1], %o call printf nop

end: ret restore

Output ____________________________

7. Bit Slinging

Write a C function named evenOrOddNumOfBits() that takes a word (unsigned int) and returns 0 if there are an

even number of 1's in the word and returns 1 if there are an odd number of 1's in the word. (12 pts)

For example, evenOrOddNumOfBits( 0x7FFFFFFF ) will return the value 1

evenOrOddNumOfBits( 0x00201000 ) will return the value 0

C

unsigned int evenOrOddNumOfBits( unsigned int word )

8. Floating Point

Convert -124.625 10 (decimal fixed-point) to binary fixed-point (binary) and single-precision IEEE floating-

point (hexadecimal) representations.

binary fixed-point __________________________________ (2 points)

IEEE floating-point __________________________________ (4 points)

Convert 0x43446000 (single-precision IEEE floating-point representation) to fixed-point decimal.

fixed-point decimal __________________________________ (6 points)

9. Machine Instructions

Translate the following instructions into SPARC machine code. Use hexadecimal values for your answers. If

an instruction is a branch, specify the number of instructions away for the target (vs. a Label).

std %o2, [%i4 + %l3] ___________________________________ (5 points)

xor %l5, -15, %i3 ___________________________________ (5 points)

Translate the following SPARC machine code instructions into SPARC assembly instructions.

0x92848006 ___________________________________ (5 points)

0xE857BFF6 ___________________________________ (5 points)

11. Load/Store/Memory

What gets printed in the following program? (9 points)

.global main

.section ".data" fmt: .asciz "0x%8x\n"! prints value as hex 0xXXXXXXXX

c: .byte 0x

.align 2 s: .half 0xABCD

.align 4 i1: .word 0x i2: .word 0x i3: .word 0x x: .word 0x

.section ".text" main: save %sp, -96, %sp

set i1, %l set s, %l

ldsh [%l1], %l st %l1, [%l0] stb %l1, [%l0+1]

set fmt, %o ld [%l0], %o call printf __________________________ nop

set i2, %l set c, %l

ldsb [%l1], %l sth %l1, [%l0+2] stb %l1, [%l0+1]

set fmt, %o ld [%l0], %o call printf __________________________ nop

set x, %l set i3, %l

ldsb [%l1], %l sth %l2, [%l0] stb %l2, [%l0+2]

set fmt, %o ld [%l0], %o call printf __________________________ nop

ret

restore

12. Miscellaneous

Put the following in the correct order/sequence using the numbers to the left of each word. (9 pts)

1. C preprocessor 4. assembler 7. C source code

2. program execution 5. compiler 8. executable (.exe/a.out)

3. Core Dump (Segmentation Fault) 6. linker/linkage editor 9. loader

_____ โ€”> _____ โ€”> _____ โ€”> _____ โ€”> _____ โ€”> _____ โ€”> _____ โ€”> _____ โ€”> _____

Draw the logic circuit to perform the following Boolean logic. Label each gate. Do not optimize. (3 pts)

!(a & b) ^ (!a | b)

Is this a sequential or combinational logic circuit? (Circle correct answer in the question to the left.) (1 pt)

When the following program is run on a Sun SPARC Unix system and sorted by the address printed with the

%p format specifier, specify the order of the lines printed from smallest value to largest value. (2 points each)

void foo( int, int ); /* Function Prototype */

int a = 43;

int main( int argc, char *argv[] ) {

int b = 7;

int c = 11;

foo( argc, b );

/* 1 */ (void) printf( "1: b --> %p\n", &b );

/* 2 */ (void) printf( "2: malloc --> %p\n", malloc(50) );

/* 3 */ (void) printf( "3: c --> %p\n", &c );

/* 4 */ (void) printf( "4: argc --> %p\n", &argc );

/* 5 */ (void) printf( "5: foo --> %p\n", foo );

void foo( int d, int e ) {

int f;

static int g;

/* 6 */ (void) printf( "6: f --> %p\n", &f );

/* 7 */ (void) printf( "7: a --> %p\n", &a );

/* 8 */ (void) printf( "8: e --> %p\n", &e );

/* 9 */ (void) printf( "9: d --> %p\n", &d );

______

______

______

______

______

______

______

______

______

______

Smallest value

Hexadecimal - Character

| 00 NUL| 01 SOH| 02 STX| 03 ETX| 04 EOT| 05 ENQ| 06 ACK| 07 BEL| | 08 BS | 09 HT | 0A NL | 0B VT | 0C NP | 0D CR | 0E SO | 0F SI | | 10 DLE| 11 DC1| 12 DC2| 13 DC3| 14 DC4| 15 NAK| 16 SYN| 17 ETB| | 18 CAN| 19 EM | 1A SUB| 1B ESC| 1C FS | 1D GS | 1E RS | 1F US | | 20 SP | 21! | 22 " | 23 # | 24 $ | 25 % | 26 & | 27 โ€™ | | 28 ( | 29 ) | 2A * | 2B + | 2C , | 2D - | 2E. | 2F / | | 30 0 | 31 1 | 32 2 | 33 3 | 34 4 | 35 5 | 36 6 | 37 7 | | 38 8 | 39 9 | 3A : | 3B ; | 3C < | 3D = | 3E > | 3F? | | 40 @ | 41 A | 42 B | 43 C | 44 D | 45 E | 46 F | 47 G | | 48 H | 49 I | 4A J | 4B K | 4C L | 4D M | 4E N | 4F O | | 50 P | 51 Q | 52 R | 53 S | 54 T | 55 U | 56 V | 57 W | | 58 X | 59 Y | 5A Z | 5B [ | 5C \ | 5D ] | 5E ^ | 5F _ | | 60 โ€˜ | 61 a | 62 b | 63 c | 64 d | 65 e | 66 f | 67 g | | 68 h | 69 i | 6A j | 6B k | 6C l | 6D m | 6E n | 6F o | | 70 p | 71 q | 72 r | 73 s | 74 t | 75 u | 76 v | 77 w | | 78 x | 79 y | 7A z | 7B { | 7C | | 7D } | 7E ~ | 7F DEL|

Scratch Paper