CISM 3330 EXAM 1 STUDY GUIDE
Bitwise Operators - Answers :& - (AND) copies a bit to the result if it exists in both
operands:
0011 1100 & 0000 1101 = 0000 1100
| - (OR) copies a bit if it exists in either operand:
0011 1100 | 0000 1101 = 0011 1101
^ - (XOR) copies the bit if it is set in one operand but not both:
0011 1100 ^ 0000 1101
~ - 'flips' bits:
~0011 1100 = 1100 0011
<< - left shift:
0011 1100 << 2 = 1111 0000
>> - right shift:
0011 1100 >> 2 = 0000 1111
File Compilation - Answers :Compilation:
c code translated into assembly (hello.s)
actual data is referenced here
text and data sections
Assemble:
Assembly code translated into machine code
object file (hello.o)
uses placeholders for memory addresses that need to be used
relocations - list of placeholders
symbol table - where the function is
Link:
Combine with other .o files
places all text/data parts in memory, then writes info into executable
gets code from libraries
Pointer arithmetic - Answers :char *hello = "Hello World";
hello + 1 ' 'e'
*(hello + 1) = 'e'
hello[1] = 'e'
Stack v Heap - Answers :Stack: stored memory from local variables (life of the function),
grows down
Heap: new and malloc, dynamic
, ATT Syntax - Answers :destination last
'( )' means in memory
'$' means constant
plain number/label means value in memory
movq $42, (%rbx) = memory[rbx] <- 42`
LEA - Answers :Load Effective adress
skips memory access, just uses memory
leaq 4(%rax), %rax = addq 4, %rax
Condition Codes - Answers :set by almost all arithmetic instructions (addq, subq, etc)
Store info on last arithmetic result
jg, jle: jump greater than, jump less than
based on the result of subtraction
0: equal, positive: greater than, negative: less than
RISC v CISA - Answers :RISC:
fewer, simpler instructions
separate instructions to access memory
fixed length instructions
more registers
no "loops" in single instructions
no instructions with 2 memory operands
few addressing modes
RISC makes simpler hardware
ISA Choices - Answers :condition codes
addressing modes
number of operands
instruction complexity
Which op codes do arithmetic? - Answers :rm, mr, pop, push, call. ret, op
how to declare typedef/struct - Answers :typedef stuct foo {
int x;
} bar;
Legal:
bar x;
struct foo x;
sub - Answers :sub rax, rbx
Bitwise Operators - Answers :& - (AND) copies a bit to the result if it exists in both
operands:
0011 1100 & 0000 1101 = 0000 1100
| - (OR) copies a bit if it exists in either operand:
0011 1100 | 0000 1101 = 0011 1101
^ - (XOR) copies the bit if it is set in one operand but not both:
0011 1100 ^ 0000 1101
~ - 'flips' bits:
~0011 1100 = 1100 0011
<< - left shift:
0011 1100 << 2 = 1111 0000
>> - right shift:
0011 1100 >> 2 = 0000 1111
File Compilation - Answers :Compilation:
c code translated into assembly (hello.s)
actual data is referenced here
text and data sections
Assemble:
Assembly code translated into machine code
object file (hello.o)
uses placeholders for memory addresses that need to be used
relocations - list of placeholders
symbol table - where the function is
Link:
Combine with other .o files
places all text/data parts in memory, then writes info into executable
gets code from libraries
Pointer arithmetic - Answers :char *hello = "Hello World";
hello + 1 ' 'e'
*(hello + 1) = 'e'
hello[1] = 'e'
Stack v Heap - Answers :Stack: stored memory from local variables (life of the function),
grows down
Heap: new and malloc, dynamic
, ATT Syntax - Answers :destination last
'( )' means in memory
'$' means constant
plain number/label means value in memory
movq $42, (%rbx) = memory[rbx] <- 42`
LEA - Answers :Load Effective adress
skips memory access, just uses memory
leaq 4(%rax), %rax = addq 4, %rax
Condition Codes - Answers :set by almost all arithmetic instructions (addq, subq, etc)
Store info on last arithmetic result
jg, jle: jump greater than, jump less than
based on the result of subtraction
0: equal, positive: greater than, negative: less than
RISC v CISA - Answers :RISC:
fewer, simpler instructions
separate instructions to access memory
fixed length instructions
more registers
no "loops" in single instructions
no instructions with 2 memory operands
few addressing modes
RISC makes simpler hardware
ISA Choices - Answers :condition codes
addressing modes
number of operands
instruction complexity
Which op codes do arithmetic? - Answers :rm, mr, pop, push, call. ret, op
how to declare typedef/struct - Answers :typedef stuct foo {
int x;
} bar;
Legal:
bar x;
struct foo x;
sub - Answers :sub rax, rbx