CPSC 2310 - DAY 14 SEPTEMBER 30, 2016 ================================================================================ MULTIPLICATION -------------- Convert the constant into a sum of powers of two (can allow a subtract) convert the multiplications by powers of two into left shifts 57x = 32x +16x +8x + x (x<<5) + (x<<4) + (x<<3) + x ^5 is from 2^5 shift by 2 powers DATA IN MEMORY -------------- variables have multiple attributes - | symbolic name | data type | storage class variable-| address in memory | byte order for multibyte variables | initialization (optional) | current value - DATA SIZES ---------- BYTE - 8 BITS = 1 BYTE - CHAR HALFWORD - 16 BITS = 2 BYTES - SHORT WORD- 32 BITS = 4 BYTES - INT DOUBLEWORD- 64 BITS = 8 BYTES - DOUBLE/LONG Alignment in byte-addressable memory memory access is typically on word-by-word basis (aligned) (original meaning of "memory word" was the unit of transfer to/from memory) alignment restrictions on load/store instructions prevent multiple-byte units from spanning across two memory words, thus allowing individual load or store instructions to make one and only one memory access -- which makes hardware easier to build. UNALIGNED ACCESS ---------------- may be illegal (system may print "Bus error (core dumped)" may cause a trap into the operating system or requires extra shifting network hardware and extra time to perform two memory access and the necessary insertion of bytes (ie to merge bytes from two memory words into the single-word-length CPU register on a load or to distribute the bytes from a register into two different memory words. ALLIGNMENT RULES ---------------- Bytes can start anywhere halfwords start on a halfword boundry words start on a word boundry doublewords start on a doubleword boundry