Yuxi Chen CS250 homework

Similar documents
Machine Language CS 3330 Samira Khan

CSCI 2121 Computer Organization and Assembly Language PRACTICE QUESTION BANK

Stack Frame Components. Using the Stack (4) Stack Structure. Updated Stack Structure. Caller Frame Arguments 7+ Return Addr Old %rbp

Machine Level Programming: Control

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory

Sample Exam I PAC II ANSWERS

How Software Executes

CS 3330 Exam 1 Fall 2017 Computing ID:

x86-64 Programming III & The Stack

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Areas for growth: I love feedback

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE351 Spring 2018, Midterm Exam April 27, 2018

CS , Fall 2007 Exam 1

Assembly II: Control Flow

Machine-Level Programming II: Control

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls

1 Number Representation(10 points)

Machine Program: Procedure. Zhaoguo Wang

Machine-Level Programming II: Control

Lecture 3 CIS 341: COMPILERS

Do not turn the page until 5:10.

Basic Data Types. CS429: Computer Organization and Architecture. Array Allocation. Array Access

Do not turn the page until 5:10.

Assembly Programming IV

Machine-Level Programming (2)

Intel x86-64 and Y86-64 Instruction Set Architecture

2. (a) Compare the characteristics of a floppy disk and a hard disk. (b) Discuss in detail memory interleaving. [8+7]

x86-64 Programming II

Computer Organization Chapter 4. Prof. Qi Tian Fall 2013

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 12

CS356 Unit 12a. Logic Circuits. Combinational Logic Gates BASIC HW. Processor Hardware Organization Pipelining

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

Recitation #6. Architecture Lab

CS429: Computer Organization and Architecture

CSE 351 Section 4 GDB and x86-64 Assembly Hi there! Welcome back to section, we re happy that you re here

C to Machine Code x86 basics: Registers Data movement instructions Memory addressing modes Arithmetic instructions

15-213/18-243, Summer 2011 Exam 1 Tuesday, June 28, 2011

CS367. Program Control

Process Layout and Function Calls

CS429: Computer Organization and Architecture

Control flow (1) Condition codes Conditional and unconditional jumps Loops Conditional moves Switch statements

How Software Executes

How Software Executes

Assembly Programming III

The Hardware/Software Interface CSE351 Spring 2013

CSC 252: Computer Organization Spring 2018: Lecture 11

Instructions and Instruction Set Architecture

Question Points Score Total: 100

last time Exam Review on the homework on office hour locations hardware description language programming language that compiles to circuits

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth

CS429: Computer Organization and Architecture

x86 Programming II CSE 351 Winter

Assembly Language II: Addressing Modes & Control Flow

CS 33. Machine Programming (2) CS33 Intro to Computer Systems XII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

The Stack & Procedures

CS 261 Fall Mike Lam, Professor. x86-64 Control Flow

x86-64 Programming III

CPSC 261 Midterm 1 Tuesday February 9th, 2016

Computer Architecture I: Outline and Instruction Set Architecture. CENG331 - Computer Organization. Murat Manguoglu

L09: Assembly Programming III. Assembly Programming III. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson

Today: Machine Programming I: Basics

CSE 351 Midterm - Winter 2017

12.1. CS356 Unit 12. Processor Hardware Organization Pipelining

CS527 Software Security

CS367 Test 1 Review Guide

CS153: Compilers Lecture 2: Assembly

CS 261 Fall Mike Lam, Professor. x86-64 Control Flow

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Part 2

Machine/Assembler Language Putting It All Together

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2

Today: Machine Programming I: Basics. Machine Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

CS 107. Lecture 13: Assembly Part III. Friday, November 10, Stack "bottom".. Earlier Frames. Frame for calling function P. Increasing address

x86 Programming I CSE 351 Winter

CS429: Computer Organization and Architecture

CS16 Exam #1 7/17/ Minutes 100 Points total

x86 64 Programming II

15-213/18-243, Fall 2010 Exam 1 - Version A

Procedures and the Call Stack

Optimization part 1 1

x86 Programming III CSE 351 Autumn 2016 Instructor: Justin Hsia

Princeton University Computer Science 217: Introduction to Programming Systems Exceptions and Processes

CSC 252: Computer Organization Spring 2018: Lecture 5

Representation of Information

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

Machine-Level Programming II: Control

Carnegie Mellon. 5 th Lecture, Jan. 31, Instructors: Todd C. Mowry & Anthony Rowe

L08: Assembly Programming II. Assembly Programming II. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson

Machine- Level Representa2on: Procedure

Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved.

%r8 %r8d. %r9 %r9d. %r10 %r10d. %r11 %r11d. %r12 %r12d. %r13 %r13d. %r14 %r14d %rbp. %r15 %r15d. Sean Barker

Recitation #6 Arch Lab (Y86-64 & O3 recap) October 3rd, 2017

Do not turn the page until 11:30.

Instruction Set Architectures

CSE P 501 Exam Sample Solution 12/1/11

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Controlling Program Flow

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

CPSC 313, Summer 2013 Final Exam Date: June 24, 2013; Instructor: Mike Feeley

Machine-Level Programming I Introduction

Transcription:

Yuxi Chen CS250 homework 1. Implement the boolean function for segment b for a 7-segment decoder. Using four switches w, x, y, z choose the digits 0, 1, 2, 3,4,5,6,7,8,9,A,B,C,D,E,F in the seven segment display. a) Write the truth table for the segment b w x y z b 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 1 0 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 1 0 b) Write the Karnaugh maps for b wx\yz 00 01 11 10 00 1 1 1 1 01 1 0 1 0 11 0 1 0 0 10 1 1 0 1 c) Using the Karnaugh maps, write the boolean expressions for segment a and b using a minimum "sum of products" boolean expression. b = w'x'+x'z'+w'y'z'+wy'z+w'yz d) Draw the schematic of your implementation using NAND gates.

2. Draw a Flip Flop a) Using NAND gates b) Using NOR gates 3. In each line write the name of the memory section where the variables are stored: int a = 5; // a is stored in data int b[20]; // b is stored in bss int main() { // main is stored in text { int x; // x is stored in stack int *p = (int *)malloc(sizeof(int)); // p points to memory stored in heap

4. Enumerate the steps needed to load a program. 1. The loader is a program that is used to run an executable file in a process. 2. Before the program starts running, the loader allocates space for all the sections of the executable file (text, data, bss etc) 3. It loads into memory the executable and shared libraries (if not loaded yet) 4. It also writes (resolves) any values in the executable to point to the functions/variables in the shared libraries.(e.g. calls to printf in hello.c) 5. Once memory image is ready, the loader jumps to the _start entry point that calls init() of all libraries and initializes static constructors. Then it calls main() and the program begins. 6. _start also calls exit() when main() returns. 5. What is a "Dynamic Linker" and a "Static Linker". A Dynamic Linker is the part of an operating system (OS) that loads and links the shared libraries for an executable when it is executed. A Static Linker puts together all object files as well as the object files in static libraries 6. Perform the following multiplication in binary. Also, show convert to decimal the operands and the result. 1001010 x 1101 1001010 * 1101 1001010 1001010 1001010 1111000010 B1001010 = 2^1+2^3+2^6 = 74 B1101 = 2^0+2^2+2^4 = 13 B1111000010 = 2^1+2^6+2^7+2^8+2^9 = 96

7. Perform the following division in binary, Also, convert to decimal the operands and the result. 1 100101001 1111 10000 0 B100101001 = 2^0+2^3+2^5+2^8 = 297 B = 2^0+2^1+2^3 = 11 B1 = 2^0+2^1+2^3+2^4 = 27 8. Represent the number1.25 in binary using the IEEE 754 double representation. The formula is given: Val in decimal = (-1) s x (1.m) x 2 (e-bias) where: bias = 1023 s = bit 63 e = bits 52 to 62 m= bits 0 to 51 Val in binary: 0011 1111 1110 0100 0000 0000 0000 0000

9. Explain what is a "Pipe Stall" and how can be avoided. Pipe Stall happens if the next instruction depends on the result of the previous instruction. To avoid stalls: Reorder the instructions Avoid introducing unnecessary branches Delay references to result register(s) 10. Obtain the representation of number -58 using 8 bits. Verify that 78 + (-58) is equal to 20 using binary addition and complements of 2. -58: 11000110 + 78: 01001110 20: 00010100 11. Write a function "int isbigendian()" that will return 1 if the computer is big endian or 0 if it is little endian. int isbigendian(){ int test=5; if (*(char*)&test==5) { return 0; else return 1; 12. What is the difference between Harvard Architecture and Von Newman Architecture In Harvard Architecture code and data are stored in separate memory, while in Von Newman Architecture code and data are stored together in memory. 13. What do CISC and RISC stand for and enumerate the characteristics of each. CISC: Complex Instruction Set Computer 1. It contains many instructions, often hundreds. 2. Some instructions take longer than others to complete RISC: Reduced Instruction Set Computer 1. It contains few instructions 32 or 64 2. Instructions have a fixed length 3. Each instruction is executed in one clock cycle.

14. Write the following characteristics of the ATMEGA328: Program Memory (KB): 32 RAM (KB): 2 Clock Speed (Hz): 20M Number of I/O ports: 23 Number of A/D ports: 6 14. Rewrite the following program in AVR assembly language. Remember that int's in AVR are 2 bytes long. int a = 6; int b = 3; int c; void setup() { c = a + b; loop() { setup: lds r24,b lds r25,(b)+1 lds r18,a lds r19,(a)+1 add r24,r18 adc r25,r19 sts (c)+1,r25 sts c,r24 ret 15. Rewrite the following program in AVR assembly language. Remember that int's in AVR are 2 bytes long. int a = 6; int b = 4; int c; void setup() { c = a * b; loop() {

setup: lds r20,b lds r21,(b)+1 lds r18,a lds r19,(a)+1 mul r20,r18 movw r24,r0 mul r20,r19 add r25,r0 mul r21,r18 add r25,r0 clr r1 sts (c)+1,r25 sts c,r24 ret 16. In x86-64 Assembly language implement the function int addarray(int n, int * array) that add all the elements of the array passed as parameter. n is the length of the array..text.globl addarray.type addarray, @function # int addarray(int n, int * array) { # // n = %rdi array = %rsi addarray: # // i = %rdx sum = %rax # movq $0,%rdx # i=0 ; movl $0,%eax # sum=0 ; # while: cmpq %rdx,%rdi # while (i<n) { // (n-i>0) jle afterw # # addl (%rsi),%eax # sum += *array; addq $1,%rdx # i++ ; addq $4,%rsi # array++ ; jmp while # afterw: ret # return sum; 17. In x86-64 Assembly language implement a program "maxmin" that prompts two integer numbers fom stdin and then displays the maximum, minimum and average of both: numbers. Here is an example of the usage: bash> maxmin a=5 b=8 max=8 min=5 avg=6

#maxmin.s.data.comm a,8.comm b,8 str1:.string str2:.string str3:.string str4:.string.text.globl main.type main: str5:.string "a=" "b=" "%d" "max=%d\n" "min=%d\n" main, @function movq $str1, %rdi call printf movq $a, %rdx movq $str3, %rax movq %rdx, %rsi movq %rax, %rdi call scanf movq $str2, %rdi call printf movq $b, %rdx movq $str3, %rax movq %rdx, %rsi movq %rax, %rdi call scanf movq $a, %rdi movq $b, %rsi movq (%rdi), %rax movq (%rsi), %rdx cmpq %rdx,%rax jg tag movq $a, %rdi movq $b, %rsi movq (%rsi), %r8 movq (%rdi), %r9 movq %r9, (%rsi) movq %r8, (%rdi)

tag: movq $a, %rdx movq (%rdx), %rsi movq $str4, %rdi call printf movq $b, %rdx movq (%rdx), %rsi movq $str5, %rdi call printf ret