Computer Organization Final Study

Ace your homework & exams now with Quizwiz!

Add one statement to the C program below so that it will compile: #include <stdio.h> void main(){ sayHello(); } void sayHello(){ static int y = 0; y++; }

#include <stdio.h> void sayHello(); void main(){ sayHello(); } void sayHello(){ static int y = 0; y++; }

Find base 10 equivalent of a number with sign = 0, exponent = 0100 1011, and fraction = 101100000000000000000000000

(-1)^0 * (1 + 0.5 + 0.125 + 0.0625) * 2^(75-127)

convert 10.111 from base 2 to base 10

(2 + 0.5 + 0.25 + 0.125) = 2.875

Which of the following are attributes of a RISC system? Choose all that apply: a) they have more registers than a CISC system b) instructions are all the same size c) instructions can do arithmetic on values located in registers and memory d) they have more instructions than a CISC system e) most instructions take the same number of clock cycles per instruction

(a) (e)

which statement about memory is false: a)each label in assembly is a symbolic name for a memory address b) a .word occupies 4 bytes c) the .asciz directive is used to allocate room for strings d) code and data are stored in a single section, indicated by the .codata directive e) the .balign directive is used to ensure that addresses are multiples of 4 bytes

(d)

which is not part of the instruction set architecture (ISA)? a) the instructions that the CPU understands b) the registers the CPU contains c) addressing modes d) data types e) trick question: these are all part of the ISA

(e)

using sign and magnitude system, what is the decimal value of 1001 1101

-29

write the .data portion of an ARM assembly program that has 3 variables, lock, stock, and bagel, with values, 10, 20, and "cream cheese" respectively

.data lock: .word #10 stock: .word #20 bagel: .asciz "cream cheese"

Write the entire .data segment, but just the portion of .text required to translate this if-else statement into ARM assembly (ignore the push {lr}, pop {lr}, and bx lr instructions, .global main, etc.). Use registers r0 and r1 in your answer if (r0 >= r1) { r1 -= 2; print("r1 shrunk"); } else { r1 += 2; puts("r1 grew); }

.data shrunk .asciz "r1 shrunk" grew .asciz "r1 grew" .text main: push {lr} cmp r0, r1 blt else sub r1, r1, #2 ldr r0, =shrunk bl puts b done else: add r1, r1, #2 ldr r0, =grew bl puts done: pop {lr} bx lr

Write the entire .data segment, but just the portion of the .text required, to translate the while loop into ARM assembly. Use registers r0 and r1, but create a separate variable, sum, to store the result int r0 = 0; int r1 = 0; while(r0 < 10) { r1 += r0; r0++; } sum = r1;

.data sum .word #0 .text main: push {lr} mov r0, #0 mov r1, #0 while: cmp r0, #10 bge end add r1, r, r0 add r0, r0, #1 b while end: ldr r5, =sum str r1 [r5] pop {lr} bx lr

Recreate the following in ARM assembly (for any variable that starts with an r, use the corresponding register). Just write the necessary code, not the entire main function, but do write the entire .data segment if (r0 * r1 < r2 + r3) { printf("Result: %d\n", r6 + r7); } else { puts("Whew!"); }

.data Res .asciz "Result: %d\n" else .asciz "Whew!" .text main: push {lr} mul r6, r0, r1 add r2, r2, r3 cmp r6, r2 bge else ldr r0, =Res add r1, r2, r6 bl printf b done else: ldr r0, =else bl puts done: pop {lr} bx lr

write a complete ARM assembly program to calculate (18 + 36) * (45 - 27). Just use immediate values. Write comments to the right of each statement. your program should be written so that the result can be displayed using echo $?

.global main .func main .text main: mov r1, #18 @r1 ← 18 mov r2, #36 @r2 ← 36 add r1, r1, r2 @r1 ← r1 + r2 mov r2, #45 @r2 ← 45 add r2, r2, #-27 @r2 ← r2 - 27 mul r0, r1, r2 @r0 ← r1*r2 bx lr

an array, arrow, contains a sequence of #RED_LED_PIN, #YELLOW_LED_PIN, and #GREEN_LED_PIN, except for the last element, which is -1 ex. in a HLL it might be: int [] arrow = {#GREEN_LED_PIN, #RED_LED_PIN, #RED_LED_PIN, #YELLOW_LED_PIN, #GREEN_LED_PIN, #GREEN_LED_PIN, #GREEN_LED_PIN, -1} In a HLL, we can iterate through it, and pass each element to a function, flash(), which causes that led to flash on and off (it is already written for you). In a HLL, it looks like this: int i = 0; while (arrow[i] != -1) { flash(arrow[i]); i++; } Write the above in ARM assembly. Store the address of the array in r7; the index (equivalent of i) in r8; and the element of the array (arrow[i]) in r9. Assume that the .data segment has already been written and that arrow is available for you to use

.text push {lr} main: ldr r7, =arrow mov r8, #0 loop: ldr r9, [r7] cmp r9, #-1 beq done mov r0, r9 bl flash add r7, r7, #4 add r8, r8, #1 b loop done: pop {lr} bx lr

convert 82 to binary using intuitive approach

0101 0010

convert the base 16 number EC97 to base 2

1110 1101 1001 0111

find 2's complement of 1111 1111 0101 1010

1111 1111 0101 1010 0000 0000 1010 0101 +1 ______________________ 1111 1111 1111 1110

Convert 1011 0110 to base 10

128 + 32 + 16 + 4 + 2

convert the base 16 number DABF to base 10

13*4096 + 10*256 + 11*16 + 15*1

write all the values from 20(sub)10 - 48(sub)10 inclusive, expressing your answer in base 16

14, 15, 16, 17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2A, 2B, 2C, 2D, 2E, 2F, 30

Express 183 in base 2, use algorithmic approach to do so

183 % 2 = 1

how many nybbles are in a byte

2

the number 37 is stored in memory, and when inspected, it appears as follows in gdb: 0x21024 25 00 00 00 is this system using big-edian or little-edian, and how do you know

37 is stored left to right

how many bytes in a word

4

how many bits in a byte

8

The idea of using r0-r3 for parameters is just one of a series of conventions called

AAPCS - ARM Architecture Procedure Call Standard

Name the component in a CU where calculations take place

ALU

name the program responsible for the task: loading things into memory and causes it to run

Loader

Name the electronic component which embeds the CPU, memory, all in one chip

Micro controller

Name the part of the CPU that is responsible for: Storing the instruction about to exectue

PC

What do the letters in RISC stand for?

Reduced instruction set computing

[T/F] Not all functions need to call push {lr} and pop {lr} --on;y ones that call another function

True

briefly, what causes a segmentation fault?

Using address as an immediate value

Fill in the table below, writing the letters s, e, and f in the cells where the sign, exponent, and fraction of an IEEE 754-formatted number would appear, respectively for the fraction, just put an f in the starting and ending cells with a line in between (f-----------------f) [31] [30 ----- 23] [22 -----------------0]

[s][e--------e][f-------------------f]

Fill in the blank, with the exponent and fraction used for the given value in IEEE 754 [value][exponent][fraction] [NaN] [ ][ ] [Infinity][ ][ ] [0] [ ][ ]

[value][exponent][fraction] [NaN] [255] [not 0] [Infinity][255] [0] [0] [0] [0]

In C, What do you need for a function to be compiled

a prototype

Match each gdb command with its purpose: a) displays memory b) executes one statement c) sets a break point d) displays the contents of r0

a) b) step c) break d) info reg r0

an int pointer, ip, has the value 0x21024, which is where the int i, with value of 2020, is located. Find the value of i and ip after these statements have executed. The statements are consecutive, so the answer to the first may affect the answer in the second: a) *ip += 2; i: _____ ip: _______ b) ip += 2; i: _____ ip: _______

a) *ip += 2; i: 2022 ip: 0x21024 b) ip += 2; i: 2022 ip: 0x2102C

Write an assembly directive to do the equivalent of each HLL statement: a) int [] arr = {20, 30, -15}; b) int [] arr2 = new int[1000];

a) .data arr .word 20, 30, -15 b) .data arr2 .skip 4000

Consider these two statements: 0x21024: bl fireTheLase 0x21028: add r0, r1, r2 ... 0x21036: fireTheLaser: @fireTheLaser's code goes here when the instruction in memory location 0x21024 executes, what value is stored a) lr? b) PC?

a) 0x21028 b) 0x21036

Show the bit pattern that results from doing each of the indicated shifts/rotates, and then express your answer as 2 hex digits. Keep a space between each nybble a) 1000 1010, LSL, #4 b) 1010 1100, ASR, #2 c) 1100 0111, ROR, #3 d) 1000 0111, ASR, #1

a) 1010 0000 : A0 b) 1110 1011 : EB c) 1111 1000 : F8 d) 1100 0011 : C3

What effect does each of the following have on the registers pc and lr? a) bl somewhere b) b somewhere_else c) beq wakanada d) bx lr

a) Effects on PC: branch and links instruction to program counter Effects on lr: Stores last place of execution b) Effects on PC: sets PC instruction to somewhere_else Effects on lr: Stores last place of execution c) Effects on PC: sets PC to instruction for wakanda if condition is met Effects on lr: Stores last place of execution d) Effects on PC: Branch and exchange the link register address Effects on lr: Stores last place of execution

a) using just hexadecimal digits A-F, find the largest 4-digit long hexadecimal number that represents an english word. (ex. BADE is a 4-digit long hexadecimal number that represents a word, but not the largest) b) express answer in base 2

a) FADE 15|10|13|14 b) 1111 1010 1101 1110

Name the addressing mode in Stars in each instruction: a) rsub r0, r1, *r2* b) str, r5, *[r5]* c) or r5, r6, *r7, LSR, #5*

a) Register address b) immediate value c) Logically shifted right by 5 registers

Write relational operator (<, <=, >, >=, ==, !=) that corresponds to each branch a) beq b) ble c) bgt d) bne e) b

a) beq: == b) ble: <= c) bgt: >= d) bne: != e) b: N/A

Write the code in ARM assembly needed to accomplish each task (use the #immediate values from class, ex. #HIGH) a) set up wiring pi to use Gpio numbering b) enable the red led in pin to be used for output c) make the blue led pin light up d) don't do anything for a half minute

a) bl wiringPiGpio cmp ro, #-1 bne init-complete b) ldr r0, #RED_LED ldr r1, #Output bl pinmode c) (there is no blue pin, HAHA) mov r0, #Blue_LED mov r1, #1 bl digitalwrite d) mov ro, #delay (30000) bl delay

when bx lr executes, what effect does it have on the contents of: a) lr b) PC

a) lr: Stores last place of execution b) PC: branches to new method

Name the ARM assembly statement needed to: a) store a value from a register into memory b) read in a value from memory into a register c) call a function

a) str b) ldr c) branch

Increment the contents of r0 by 10

add r0, r0, #10

Write the Raspian command to: assemble a program, first.s, and output it to an object file first.o

as -g -o first.s first.o

name the program responsible for the task: convert assembly language into machine code

assembler

what is the very last line of any function?

bx lr

provide the raspian command for: relocate to the /home/guest/X directory

cd /home/guest/x

provide the raspian command for: clear the screen

clear

name the program responsible for the task: convert a HLL into assembly language

compiler

Special Function Registers: stores condition flags (was the last result zero? was there an overflow? etc.

cpsr

what is meant by the "little end" of a number

depending on big-edian or little-edianm the smallest size numbers reside on the "little end"

name the program responsible for the task: debug a program (name the debugger used in class)

dgb

Write the Raspian command to: display the condition code returned by a program

echo $?

A global variable or function is declared in another file

extern

declare an int, height, initialized to 10, and a pointer to height, heightPtr, initialized to the address of height

int height = 10; int *heightPtr = &height;

Declare years, an int array, with 5 elements

int years[5];

name the program responsible for the task: Link object modules together to get an executable program

linker

Name the part of the CPU that is responsible for: Storing the address of the next instruction to be executed

lr

Write the Raspian command to: list the contents of the /dev directory, including invisible files

ls -a -l /dev

provide the raspian command for: list the files in /dev, showing detail (time stamp, permissions, etc.)

ls -l -a /dev

Write the Raspian command to: make a directory called A

mkdir A

provide the raspian command for: make two directories: C and D

mkdir C mkdir D

Write an ARM statement to place the number 23 into register r0

mov r0, #23

explain briefly what the statement does: cd ../..

moves up two directories

Write an ARM statement to triple the contents of r0, storing the result in r1. Use only instructions that start with the letter m

mul r1, r0, #3

Write the Raspian command to: rename the director A as Eh

mv A Eh

provide the raspian command for: rename greet.s as go.s

mv greet.s go.s

Write the Raspian command to: edit a file, first.s, using the editor that we have been using in class

nano first.s

print out, in one statement, the following: Height:_----.-- HeightPtr:_-------- where each dash represents a digit, each _ a space

printf("Height: %.2d HeightPtr: %d", height, heightPrt);

Write the Raspian command to: print the name of the working directory

pwd

Special Function Registers: points to the top of a stack that is used when functions are called

r13 (stack pointer)

Special Function Registers: stores the return address so after a function is called execution can resume at the correct location

r14 (link register)

Special Function Registers: contains the address of the next instruction to execute

r15 (program counter)

provide the raspian command for: delete the directory C

rm dir C

provide the raspian command for: delete the file go.s

rm go.s

Using the algorithmic approach, express 9.0 in IEEE 754 format. sign: exponent: fraction:

sign: 0 exponent: (9/2)^3 * 2^3 => 1.125*2^3 fraction: 0.125 * 2 = 0.25 0.25 * 2 = 0.5 0.5 * 2 = 1 0 * 2 = 0 0 1000 0010 0010 (-1)^0 * (1+0.125) * 2^(130-127)

A function should be visible only in this particular file

static

A local variable will retain its value from one function call to another

static

Declare a struct vehicle, storing it in the variable garage

struct vehicle garage;

Declare a struct vehicle array garage, with 2 structs. Initialize them to values: with two fields, {int numSeats, double, price}

struct vehicle garage[2] = {{4, 12,000.00}, {6, 20000.00}};

Declare a struct, vehicle, with two fields, an int numSeats, and a double, price

struct vehicle { int numSeats; double price; };

provide the raspian command for: add a user, susan, to the system

sudo adduser susan

provide the raspian command for: install the programs fame

sudo apt-get install fame

The IR in a CPU contains a number. What does this number represent

the next instruction to be done

the PC in a CPU contains a number. what does that number represent

the top of the stack

provide the raspian command for: create a new empty file, greet.s

touch greet.s

explain briefly what the statement does: cat tofu.txt

writes/prints out contents


Related study sets

Public Speaking Chapter 6: Analyzing the Audience

View Set

Sociology 1010 final exam review

View Set

Patho Exam 2: Chapter 10 Infectious Disease   

View Set

Lesson1:Solve linear Equations in one variable

View Set