Seminar assignments - Hw 1-3 and solutions PDF

Title Seminar assignments - Hw 1-3 and solutions
Course Introduction to Low-level Programming and Computer Organization
Institution Ohio State University
Pages 25
File Size 1.3 MB
File Type PDF
Total Downloads 32
Total Views 147

Summary

HW 1-3 and solutions...


Description

CSE2421 SPRING 2013 HOMEWORK#1

Due Date: 3/1/2013 11:59pm

1. Google why use assembly language? “peif 5 diffeet wesites that aswe this uestio in as many different ways as possible; and write a short paragraph from each *in your own words* (i.e. do NOT copy/paste) to explain the reason and importance (or lack thereof) for using assembly language. 2. Define the following as it relates to computer science: a. Address bus b. Data bus c. Word (i.e. word size) d. Pipelining e. Address Alignment f. ISA (instruction set architecture) g. Load/Store architecture 3. Show your work to convert the following non-decimal values into the base 10 equivalent. You can check your work with a program or calculator, but you must write out the long format of how the resulting calculation was determined for each problem. a. (12345)6 = (__________)10 b. (12345)7 = (__________)10 c. (12345)9 = (__________)10 d. (1010020321)4 = (__________)10 e. (122010211)3 = (__________)10 4. Show your work to convert the following base 10 values into the specified base equivalent. You can check your work with a program or calculator, but you must write out the long format of how the resulting calculation was determined for each problem. a. (1,231)10 = (_________)4 b. (1,231)10 = (_________)8 c. (99,999)10 = (_________)2 d. (5,987,321)10 = (_________)6 e. (55,555)10 = (_________)5 5. Explain why this is always true: 10X = X10 6. There is a shortcut way of converting from binary to hex and octal. Assuming that the colored boxes represent a bit value of 1 and the non-colored boxes represent a bit value of 0, use this shortcut method to fill in the HEX and OCT columns to designate the equivalent value in these different bases. MSB

LSB

HEX

OCT

7. Assume that each of the following five values is stored as a 32-bit integer value; and these 5 values are being stored sequentially in memory starting at address 0x200. Show the hex version of memory for both the big endian and little endian (as designated) byte addressing shees. Be sue to eted the Bte ode olu speifig the correct address values for each byte of memory needed to store these 5 values. HINT: 32-bits is 4 bytes, so 5 values at 4-bytes each would be a total of 20 bytes of memory. a. 0xAB124CD1 Byte Big Little order Endian Endian b. 0x2AF567 0x200 c. 0x9A0C5 0x201 d. 0x1 0x202 e. 0x123ABCD 0x203 0x204 0x205 0x206 0x207

etc 8. Write a C program to print the minimum and maximum values as designated by the #define directive in the limits.h file; and as pertains to the C language on the X86 architecture (i.e. on our system). Write both the signed and unsigned values to the screen for the following types: a. Minimum character value e. Minimum integer value b. Maximum character value f. Maximum integer value c. Minimum short integer value g. Minimum long integer value d. Maximum short integer value h. Maximum long integer value HINT: hee’s a deet wesite: http://tigcc.ticalc.org/doc/limits.html; but there are others. Given the following binary value, 0011001100110011, convert it to a decimal value for each of the specified integer formats; and show the character value for the text format. Show/explain your work where applicable. a. Text Unicode d. Integer B2O b. Integer unsigned (B2U) e. Integer B2S c. Integer signed (B2T) Given the following binary value, 1011001100110011, convert it to a decimal value for each of the specified integer formats; and show the character value for the text format. Show/explain your work where applicable. a. Text Unicode d. B2O b. Integer unsigned (B2U) e. B2S c. Integer signed (B2T) Given the decimal value 199, convert it to the equivalent hex value for each of the specified formats. Show/exlain your work where applicable. a. Integer unsigned (B2U) c. B2O b. Integer signed (B2T) d. B2S

Given the decimal value -123, convert it to the equivalent hex value for each of the specified formats. Show/explain your work where applicable. a. Integer unsigned (B2U) c. B2O b. Integer signed (B2T) d. B2S

CSE2421 SPRING 2013 HOMEWORK#1

Due Date: 3/1/2013 11:59pm

1. (5 pts) Google why use assembly language? “peif 5 diffeet websites that answer this question in as many different ways as possible; and write a short paragraph from each *in your own words* (i.e. do NOT copy/paste) to explain the reason and importance (or lack thereof) for using assembly language. Part 1. http://www.vbforums.com/showthread.php?390024-Why-use-Assembly-language Assembly language is very useful for routines that require high speed and highly optimized code. It is also required for Boot Loaders (i.e. LILO, GRUB, etc...) and Operating Systems. HLLs tend to be bloated, mainly due to the multiple levels of abstraction that separates native binary from the HL language in question. Part 2. http://www.thornley.net/~thornley/david/squirrel/squirrelasm.html Assembly language is a way of telling the computer exactly what to do, as specifically as possible. It compiles directly to "machine code", which is the most exact method of controlling an existing computer. All languages compile to machine code, except for interpreted ones, which are therefore less in control. Issues to think about: performance, optimizations, ease of use, maintenance, portability, and educational value. Part 3. http://www.codeproject.com/Articles/89460/Why-Learn-Assembly-Language Advantages: Assembly language gives you complete control over the system's resources. Much like an assembly line, you write code to push single values into registers, deal with memory addresses directly to retrieve values or pointers. To write in assembly is to understand exactly how the processor and memory work together to "make things happen". Disadvantages: Be warned, assembly language is cryptic, and the applications source code size is much much larger than that of a high-level language. Also, Understanding disassembly view of an executable program is also useful:  for investigating the cause of a serious bugs or crashes that require understanding of memory dumps and disassembled code  for optimizing your code  for practical and educational purposes Part 4. http://www.c-jump.com/CIS77/ASM/Assembly/lecture.html#A77_0020_assembly_disadvantages Disadvantages:  Assembly language programs are not portable!  Learning the assembly is more difficult than learning Java!  Programming in the assembly language is a tedious and error-prone process.  High-level languages should be natural preference for common applications. Part 5. http://moss.csc.ncsu.edu/~mueller/codeopt/codeopt00/notes/intro.html Why USE Assembly language?  Old reason: To get very efficient code in time-critical places. No longer true. Compilers generate better code than almost all assembly language programmers. Because of hardware improvements, this kind of speed is mostly redundant.  Valid Reason: Need access to specific hardware features or instructions, eg. set interrupt level in state register - cannot be done in any HLL. This occurs in system programming and is implemented via assembly language subprograms. OK, then, Why STUDY Assembly Language?  Needed for a full understanding of HLLs and the reason for some of their unusual rules.  Needed in order to write many programs well (to understand efficiency issues) especially in parallel computers.  Needed to write or understand compilers, interpreters, debuggers.  The basis for understanding computer hardware and computer organization (74.337).  To be a "Computer Scientist": This is the way ALL software runs and what ALL hardware has as its core function.

2. (7 pts) Define the following as it relates to computer science: a. Address bus A collection of wires connecting the CPU with main memory that is used to identify particular locations (addresses) in main memory. Determines how many unique memory locations can be addressed. b. Data bus Transfers data from one component to another; includes transferring data to and from memory, the CPU, etc. This is how many bytes you can transfer at a time. Another name for the data bus is adidth. c. Word (i.e. word size) The number of bits a CPU can process at one time. d. Pipelining Pipelining is an implementation technique where multiple instructions are overlapped in execution. Pipelining does not decrease the time for individual instruction execution. Instead, it increases instruction throughput. The throughput of the instruction pipeline is determined by how often an instruction exits the pipeline. e. Address Alignment Certain architectures rule that memory accesses must meet some certain alignment criteria or are otherwise illegal. The exact criteria that determines whether an access is suitably aligned depends upon the address being accessed and the number of bytes involved in the transaction, and varies from architecture to architecture. f.

ISA (instruction set architecture) The Instruction Set Architecture (ISA) is the part of the processor that is visible to the programmer or compiler writer. The ISA serves as the boundary between software and hardware.

g. Load/Store architecture Only allows memory to be accessed by load and store operations 3. (5 pts) Show your work to convert the following non-decimal values into the base 10 equivalent. You can check your work with a program or calculator, but you must write out the long format of how the resulting calculation was determined for each problem. a. (12345)6 = (__________)10  1,865 b. (12345)7 = (__________)10  3,267 c. (12345)9 = (__________)10  8,303 d. (1010020321)4 = (__________)10  279,097 e. (122010211)3 = (__________)10  12,496 4. (5 pts) Show your work to convert the following base 10 values into the specified base equivalent. You can check your work with a program or calculator, but you must write out the long format of how the resulting calculation was determined for each problem. a. (1,231)10 = (_________)4  103033 b. (1,231)10 = (_________)8  2317 c. (99,999)10 = (_________)2  1 1000 0110 1001 1111 d. (5,987,321)10 = (_________)6  332155025 e. (55,555)10 = (_________)5  3234210

5. (2 pts) Explain why this is always true: 10X = X10 The number of digits for base x is x digits whose values range from 0 to x-1. So in general, adding 1 to the x-1 digit equates to putting down a zero and carrying a one; and one more than the maximum digit (1 plus x-1) is eual to … thus, 2 = 210 and 103 = 310 and 104 = 410, etc. 6. (17 pts) There is a shortcut way of converting from binary to hex and octal. Assuming that the colored boxes represent a bit value of 1 and the non-colored boxes represent a bit value of 0, use this shortcut method to fill in the HEX and OCT columns to designate the equivalent value in these different bases. MSB

LSB

HEX

OCTAL

800000 880000 800000 EA8400 AB4EA5

40000000 42000000 40000000 72502000 52647245

AA2AD5 AA2A85 EA2687 000001

52425325 52425205 72423207 00000001

000801 101403

00004001 04012003

001000 171000

00010000 05610000

143AA8 1712B4

05035250 05611264

1112A4 1713A4

04211244 05611644

7. (20 pts) Assume that each of the following five values is stored as a 32-bit integer value; and these 5 values are being stored sequentially in memory starting at address 0x200. Show the hex version of memory for both the big edia ad little edia as desigated te addessig shees. Be sue to eted the Bte ode olu specifying the correct address values for each byte of memory needed to store these 5 values. HINT: 32-bits is 4 bytes, so 5 values at 4-bytes each would be a total of 20 bytes of memory. a. 0xAB124CD1 Byte Big Little b. 0x2AF567 order Endian Endian c. 0x9A0C5 0x200 AB D1 d. 0x1 0x201 12 4C e. 0x123ABCD 0x202 4C 12 0x203 D1 AB 0x204 00 67 0x205 2A F5 0x206 F5 2A 0x207 67 00 0x208 00 C5 0x209 09 A0 0x20A A0 09 0x20B C5 00 0x20C 00 01 0x20D 00 00 0x20E 00 00 0x20F 01 00 0x210 01 CD 0x211 23 AB 0x212 AB 23 0x213 CD 01 8. (8 pts) a C program to print the minimum and maximum values as designated by the #define directive in the limits.h file; and as pertains to the C language on the X86 architecture (i.e. on our system). Write both the signed and unsigned values to the screen for the following types: a. Minimum character value e. Minimum integer value b. Maximum character value f. Maximum integer value c. Minimum short integer value g. Minimum long integer value d. Maximum short integer value h. Maximum long integer value HINT: hee’s a deet esite: http://tigcc.ticalc.org/doc/limits.html; but there are others. The studets ee asked to ite a C poga ith the itet that the tu it i… the idea was to look up the #define variable to designate the min/max values, not redefine the actual limit values (already know how to calculate these). type minimum signed minimum unsigned maximum signed maximum unsigned char SCHAR_MIN 0 SCHAR_MAX UCHAR_MAX short integer SHRT_MIN 0 SHRT_MAX USHRT_MAX integer INT_MIN 0 INT_MAX UINT_MAX long integer LONG_MIN 0 LONG_MAX ULONG_MAX FYI: any minimum unsigned value has a value of zero; there is no #define name for these values.

9. (5 pts) Given the following binary value, 0011001100110011, convert it to a decimal value for each of the specified integer formats; and show the character value for the text format. Show/explain your work where applicable. a. Text Unicode – 0x3333 is a SQUARE HUIITO symbol which looks like:

b. c. d. e.

Integer unsigned (B2U)  13,107 Integer signed (B2T)  same as B2U Integer B2O  same as B2U Integer B2S  same as B2U

B2U – show work by using multiplication of powers. Explanation for c, d, and e being the same is since the given binary value has a left most bit of 0, it is a positive number and all of the positive values in each representation are the same.

10. (10 pts) Given the following binary value, 1011001100110011, convert it to a decimal value for each of the specified integer formats; and show the character value for the text format. Show/explain your work where applicable. a. Text Unicode – 0xB333 is a Hagul sllale hih looks like:

b. c. d. e.

Integer unsigned (B2U)  45,875 Integer signed (B2T)  -19,661 B2O  -19,660 B2S  -13,107

B2U – show work by using multiplication of powers B2T – show work by using multiplication of powers; or -215 + 26,214 B2O – iet the its ut do’t add one more to the negative value so one different (toward zero) than B2T B2S – magnitude is same as B2U in previous problem

11. ( 8 pts) Given the decimal value 199, convert it to the equivalent hex value for each of the specified formats. Show/explain your work where applicable. B2U – show work by using repeated division. Explanation a. Integer unsigned (B2U)  0xC7 for b, c, and d being the same is since the given value is a b. Integer signed (B2T)  same as B2U c. B2O  same as B2U positive number; and all of the positive values in each d. B2S  same as B2U representation are the same. 12. (8 pts) Given the decimal value -123, convert it to the equivalent hex value for each of the specified formats. Show/explain your work where applicable. a. Integer unsigned (B2U)  cannot represent a negative value in B2U b. Integer signed (B2T)  0xFF85 c. B2O  0xFF84 d. B2S  0xFB (8-bit) i.e. 123 = 111 1011 so depends on width as to where the 1 sign bit goes; 1000 0111 1011 if do 12-bit which is 0x87B in hex (etc) B2T – show work by using repeated division with positive 123 to get the binary; then invert the bits and add 1 to get the negative value; convert to hex B2O – oe less tha BT sie iet ut do’t add  B2S – use the positive 123 binary from B2T calc and put a 1 as the left most bit NOTE: optional more/less F (or 1 bit) values to the left of 0x85/0x84 since no width specified

CSE2421 SPRING 2013 HOMEWORK#2

Due Date: 3/8/2013 11:59pm

1. When adding the following two 4-bit binary values, 1011 and 0110, specify the following for each of the 4-bit column additions CARRY IN = 0 (first carry-in defaults to zero) A = 1 (given) B = 0 (given) SUM = CARRY (out of gate#2) = SUM_OUT = CARRY (out of gate#4) = CARRY OUT = CARRY IN = A = 1 (given) B = 1 (given) SUM = CARRY (out of gate#2) = SUM_OUT = CARRY (out of gate#4) = CARRY OUT =

CARRY IN = A = 0 (given) B = 1 (given) SUM = CARRY (out of gate#2) = SUM_OUT = CARRY (out of gate#4) = CARRY OUT = CARRY IN = A = 1 (given) B = 0 (given) SUM = CARRY (out of gate#2) = SUM_OUT = CARRY (out of gate#4) = CARRY OUT =

2. Give n the width of the binary representation (i.e. the number of bits column) and the type of representation (signed or unsigned), determine how many values can be represented in the given width, as well as the minimum and maximum values that can be represented in the given width. Assume that the unsigned type means B2U and the signed type means B2T. # of BITS

TYPE

6

signed

6

unsigned

7

signed

7

unsigned

10

signed

10

unsigned

20

signed

20

unsigned

# of Values

Min Value

Max Value

3. With respect to # of values, minimum value and maximum value (per the above problem), specify the difference(s) between B2T, B2O and B2S. 4. Specify the carry and result for each set of a+b; then, if one or more of the overflows occur, specify why in the box provided. positive overflow carry --> +

a = 0101 1110 b = 0001 0111

+

a = 1100 1010 b = 1010 0101

+

a = 0101 1010 b = 0111 0001

+

a = 0101 0110 b = 1001 0110

result --> carry -->

result --> carry -->

result --> carry -->

result -->

negative overflow

unsigned overflow

5. Assuming the 8-bit value is a signed value (B2T), determine the negation, truncation to 4-bit and sign extend to 12bit of the original 8-bit value. 8-bit value 0000 0000 0001 1101 1010 0010 1111 1111

negate

truncate to 4-bit

sign extend 12-bit

6. Show how addition and shifting (only) can be used to determine the result of 10*60. Hint: See the slides on ultiplig  ostats. How does our eplaatio i.e. the workig out of the prole solutio hage if our constant value is negative? 7. Given x = -69 (i.e. signed integer) and y = 2k, determine the values as designated by each column heading (see the signed integer division by 2k slides).

k 0 1 2 3 4 5

y 1 2 4 8 16 32

Binary of x right shifted by k

Decimal

x/y

(x+y-1)/y

x/y rounded up

(x+y-1)/y rounded down

8. Based on the value given in the first column, determine the result for each of the different rounding options specified when rounding to the nearest whole number. round round round towards away from round to value round up down nearest zero zero -64.75 -50.00 -33.50 -11.37 0.00 25.50 47.76 60.00 72.25

9. Determine the IEEE standard 32-bit binary representation for each of the following float values: a. 1,234.567 b. -101.112255 Show all of your work and include a few comments as to what you are doing at each step.

CSE2421 SPRING 2013 HOMEWORK#2

Due Date: 3/8/2013 11:59pm

1. (12 pts) When adding the following two 4-bit binary values, 1011 and 0110, specify the following for each of the 4bit column additions CARRY IN = 0 (first carry-in defaults to zero) A = 1 (given) B = 0 (given) SUM = 1 CARRY (out of gate#2) = 0 SUM_OUT = 1 CARRY (out of gate#4) = 0 CARRY OUT = 0 CARRY IN = 0 A = 1 (given) B = 1 (given) SUM = 0 CARRY (out of gate#2) = 1 SUM_OUT = 0 CARRY (out of gate#4) = 0 CARRY OUT = 1

CARRY IN = 1 A = 0 (given) B = 1...


Similar Free PDFs