Computer Architecture Cheat Sheet for Exam 1, Study notes of Advanced Computer Architecture

This comprehensive cheat sheet provides a concise overview of key concepts in computer architecture, covering topics such as char and pointers, pointer arithmetic, derived data types, arrays, structs, floating-point numbers, memory management, printf arguments, ascii table, linux commands, and c programming concepts. It includes important formulas, bit manipulation techniques, and essential information for exam preparation.

Typology: Study notes

2022/2023

Uploaded on 09/14/2024

webteryuth
webteryuth ๐Ÿ‡บ๐Ÿ‡ธ

2 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cheat Sheet for Exam 1:
Notes for this document
This document is designed to be an aid for the exam, containing common notes, memorized values,
etc. that would be useful for the exam. Feel free to add on to this document (its a collaborative effort!).
IF THERE ARE ANY TOPICS MISSING, PLEASE ADD THEM BELOW!
IMPORTANT NOTE: Download the document before the exam starts, as live google docs are not
allowed on the exam. Make sure to do it right before because it will be continually updated as needed
Char and Pointers
A char is just an unsigned byte (ASCII): arithmetic is easily applied: โ€˜dโ€™ - 3 = โ€˜aโ€™
UTF+8 is an alternative to ASCII that uses anywhere from 1-4 bytes of memory, and so is usually
written in hex format like so) the mathematical โˆซ symbol: U+222B.
Pointer Arithmetic
Scalars will automatically scale to the size of the datatype that the pointer points to.
Ex: say we have an integer pointer int *i.
i + 3
= 0 + (sizeof(int) * 3)
= 0 + (4 * 3)
= 12 bytes offset from i, which is useful if trying to access i[3].
Ex: say matptr is a pointer to a struct called mat that has a size 16.
(char *)(matptr + 8) + 8
= (char *)(0 + sizeof(mat) * 8) + 8
= (char *)(0 + 16 * 8) + 8
= 128 + (sizeof(char) * 8)
= 128 + (1 * 8)
= 128 + 8
= 136 bytes, S2022 โ€œDerived data typesโ€ questions
Derived Data Types
sizeof(char) == 1
sizeof(short) == 2
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Computer Architecture Cheat Sheet for Exam 1 and more Study notes Advanced Computer Architecture in PDF only on Docsity!

Cheat Sheet for Exam 1:

Notes for this document

This document is designed to be an aid for the exam, containing common notes, memorized values, etc. that would be useful for the exam. Feel free to add on to this document (its a collaborative effort!). IF THERE ARE ANY TOPICS MISSING, PLEASE ADD THEM BELOW! IMPORTANT NOTE: Download the document before the exam starts, as live google docs are not allowed on the exam. Make sure to do it right before because it will be continually updated as needed

Char and Pointers

A char is just an unsigned byte (ASCII): arithmetic is easily applied: โ€˜dโ€™ - 3 = โ€˜aโ€™ UTF+8 is an alternative to ASCII that uses anywhere from 1-4 bytes of memory, and so is usually written in hex format like so) the mathematical โˆซ symbol: U+222B.

Pointer Arithmetic

Scalars will automatically scale to the size of the datatype that the pointer points to. Ex: say we have an integer pointer int *i. i + 3 = 0 + (sizeof(int) * 3) = 0 + (4 * 3) = 12 bytes offset from i, which is useful if trying to access i[3]. Ex: say matptr is a pointer to a struct called mat that has a size 16. (char *)(matptr + 8) + 8 = (char *)(0 + sizeof(mat) * 8) + 8 = (char *)(0 + 16 * 8) + 8 = 128 + (sizeof(char) * 8) = 128 + (1 * 8) = 128 + 8 = 136 bytes, S2022 โ€œDerived data typesโ€ questions

Derived Data Types

sizeof(char) == 1 sizeof(short) == 2

sizeof(int) == 4 sizeof(float) == 4 P = 24 sizeof(long) == 8 sizeof(double) == 8 P = 53 Q = 11 sizeof(void*) == 8. Likewise for any unsigned variants.

Arrays

Say we have the array: T x[N] (T is the type, and N is how many elements). In memory, the array is just the data in sequential order. The address at x is the address of x[0]. Under the hood, when we say x[n], we are getting the address at x[0] + (sizeof(T) * n) (See above for sizeof()). If we want to find the last byte of x[n], we can say its address is at x[0] + (sizeof(T) * (n + 1)) - 1. So the range of byte addresses of x[n] is :[x[0] + (sizeof(T) * n), x[0] + (sizeof(T) * (n + 1)) - 1] Say we have the multidimensional array T y[M][N]: We can say y is an array of M arrays of N. The row of N is consecutive.

Size of a Struct

A struct (our example will just be a char, int, and a short) in memory is in the order it was declared in. When calculating the size of a struct, you must sequentially put each member into memory. However, the memberโ€™s memory must be aligned to its size (Every integer must be on a mod x address (4,8,4032)). In order to make sure it does, you can add padding to make sure everything is aligned. Add padding at the end to make the entire struct mod the largest val. Here is an example:

Struct with Union Padding

While padding a union, we pad to the largest parameter inside the union.

Floating Point Arithmetic: Look in powers of 2. If it cannot be written with the amount of bits you have. You can either round up, (x+) or round down (x-). Rounding down is truncating the true representation. Rounding up is truncating the true representation and then adding 1 to the lsb (least significant bit). By default, floating point is round to closest and breaking ties with making even (if your lsb is 0, leave it, if it is 1, add 1 to make it

Memory Management

Coalescing: Combining two adjacent, free blocks in memory into one free block Bump Allocator: Calling csbrk every time memory is needed. NOTE: Does not have freeing External Fragmentation: โ— Coalescing handles this Internal fragmentation: โ— Best-fit minimizes this โ— Caused by splitting blocks

Common printf arguments

Integer Format Specifiers

โ— %d or %i: Print an int as a signed decimal number. โ— %u: Print an unsigned int as an unsigned decimal number. โ— %o: Print an unsigned int as an octal number. โ— %x or %X: Print an unsigned int as a hexadecimal number. %x produces lowercase letters (a-f), and %X produces uppercase letters (A-F). โ— %c: Print the corresponding ASCII character of an unsigned char or char.

Floating-Point Format Specifiers

โ— %f: Print a double in fixed-point notation. For floating-point (float), it's promoted to double when passed to printf. โ— %e or %E: Print a double in scientific notation. %e produces lowercase (e.g., e+01), and %E produces uppercase (e.g., E+01). โ— %g or %G: Print a double in either fixed-point or scientific notation, whichever is shorter, with insignificant zeroes not printed. %g uses lowercase, and %G uses uppercase.

Important Links and Sources

Ascii (and UTF-8) to text converter: https://www.rapidtables.com/convert/number/hex-to-ascii.html Float calculator: (https://observablehq.com/@benaubin/floating-point ) https://www.h-schmidt.net/FloatConverter/IEEE754.html Unicode padding chart: b4DQmHnmpe1h85fKlpLAE9Dv (edusercontent.com) NOTE: Windows, Mac, and Linux have a programming calculator with basic bit logic, shifters, and hex/binary converters Past exams in pdf format: https://cdn.discordapp.com/attachments/1196607459729625239/1210668077398761533/Comp_Arch_ Past_Exam_1_Questions.pdf?ex=65eb6582&is=65d8f082&hm=d5d2e271c032e287fc1f4fa167fda 20fc0e73252c9ab04923c76c32a7698& https://static.us.edusercontent.com/files/XtsvgU4A9Cex9mKHpbHpX6zs ASCII Table

Import things to remember:

โ— Linux

โ—‹ Cd - change directory โ—‹ Pwd- print working directory โ—‹ Ctrl l - clear โ—‹ ~ - home directory โ—‹. - current directory โ—‹ .. - parent directory โ—‹ Ls - listing โ—‹ LS - L - long listing โ—‹ Rm - remove

โ— C

โ—‹ String - null terminated array of chars โ—‹ To dereference pointer, use *. โ—‹ To get value of object from pointer, use -> โ—‹ To get memory address, use & โ—‹ Address of thing starts at lowest memory address โ—‹ Little endian - least significant byte first โ—‹ Big endian - most significant byte first

โ— Math

โ—‹ Twoโ€™s complement - most significant bit represents negative value โ—‹ Signed addition can only overflow if and only if the signs are the same โ—‹ Expand unsigned bits, add 0s to front โ—‹ Expand signed bits, add sign bit to front โ—‹ Bit operators, &, |, ^, <<, >> โ–  Right shifts are arithmetic on the exam(fill in with sign bit) โ—‹ 2^w(word size)-1 = num bits needed for pointer

โ—‹ 8 bits = 1 byte โ—‹ Additive inverse = flip all bits, then add 1 โ—‹ For unsigned โ–  Machine add = (x + y) % 2n โ–  Machine subtract = x + yโ€™s additive inverse โ–  Machine multiply = x * y % 2n โ—‹ For signed, be careful because overflow, use signed and unsigned number wheel โ–  Machine add = (x + y) % 2(n-1)- โ–  Machine subtract = x + 2โ€™s complement of y โ–  Machine multiply = x * y % 2n โ—‹ Full adder adds one bit position โ—‹ Ripple carry adder is multiple full adders โ—‹ When subtracting with adder, we know that carry in for the first block will be 1, (bc additive inverse) but it will be zero for adding. โ—‹ Masking = use another bit pattern to extract info out of your bits โ—‹ Recursive doubling = weird divide and conquer algorithm for bits โ–  Four facts: โ— Associative operator โ— Log2 size of var lines of code โ— * or / by 2 โ— masks have pattern โ–  Should try 2^k and 2^k-1, to determine what bit is doing โ—‹ Fixed-point- extend decimal point โ—‹ Floating point- change spacing so step size is variable โ–  1 bit for Sign, q bits for exponent, p-1 bits for significand โ— Donโ€™t forget hidden bit trick, 1 is implicit, is 0 if all exponent 0 โ–  Subnormal numbers is when all expo is 0 โ–  All 111s in expo and 000s in significand is infinity โ–  All 11s in expo and significand != 0 is NAN โ–  For rounding โ— Round down is x-(chop off b bits you donโ€™t have) โ— Round up is x+(make lsb 1) โ— Round to 0 is if x>0 x- else x+ โ— Round to nearest is whichever is closest to x โ— If x > Nmax then x- = Nmax x+ = infinity โ— If x <Nmin then x- = subnormal or 0 x+ either subnormal or Nmin

Formulas

โ— Machine epsilon = 2-(p-1)^ = 2(1-p) โ— Ulp(x) = Machine epsilon * 2E^ (where E is the exponent of x) โ— Bias = 2(q-1)- โ— Emin = - (bias - 1) = 1 - bias โ— Nmin = (0 p-2 times, then a 1 at the end) * 2Emin, sign bit

MOSFET - Metal-Oxide-Semiconductor Field-effect transistor โ— Amplify signals The unsigned k-bit number wheel, and the corresponding set on the signed k-bit number wheel have the SAME maximum (2^k-1) but different minimums (0 & -2^k respectively) Ferromagnetism - โ— Hard disk drives โ— Magnetic dipoles

Please feel free to add more sections down here! (Or wherever we aint your

mom)