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

Size: px
Start display at page:

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

Transcription

1 last time Exam Review hardware description language programming language that compiles to circuits stages as conceptual division not the order things happen easier to figure out wiring stage-by-stage? 1 2 on office hour locations on the homework can use multiple statements and temporary variables only arithmetic shifts available 3 4

2 on this week s quiz 5 6 layers of abstraction interlude: powers of two x += y add %rbx, %rax SIXTEEN Higher-level language: C Assembly: X6-64 Machine code: Y6??? Gates / Transistors / Wires / Registers K (or Ki) M (or Mi) G (or Gi)

3 processors and memory endianness processor memory Images: Single core Opteron xx die: Dg2fer at the German language Wikipedia, via Wikimedia Commons SDRAM by Arnaud 25, via Wikimedia Commons 7 address FFFFFFF FFFFFFE FFFFFFD 0x x x x x x x x00041FFF 0x00041FFE 0x x x value 0x14 0x45 0xDE 0x06 0x05 0x04 0x03 0x02 0x01 0x00 0x03 0x60 E 0xE0 0xA0 int *x = (int*)0x42000; cout << *x << endl; endianness endianness address FFFFFFF FFFFFFE FFFFFFD 0x x x x x x x x00041FFF 0x00041FFE 0x x x value 0x14 0x45 0xDE 0x06 0x05 0x04 0x03 0x02 0x01 0x00 0x03 0x60 E 0xE0 0xA0 int *x = (int*)0x42000; cout << *x << endl; address FFFFFFF FFFFFFE FFFFFFD 0x x x x x x x x00041FFF 0x00041FFE 0x x x value 0x14 0x45 0xDE 0x06 0x05 0x04 0x03 0x02 0x01 0x00 0x03 0x60 E 0xE0 0xA0 int *x = (int*)0x42000; cout << *x << endl; 0x = x = 66051

4 endianness endianness address FFFFFFF FFFFFFE FFFFFFD 0x x x x x x x x00041FFF 0x00041FFE 0x x x value 0x14 0x45 0xDE 0x06 0x05 0x04 0x03 0x02 0x01 0x00 0x03 0x60 E 0xE0 0xA0 int *x = (int*)0x42000; cout << *x << endl; 0x = little endian (least significant byte has lowest address) 0x = big endian (most significant byte has lowest address) address FFFFFFF FFFFFFE FFFFFFD 0x x x x x x x x00041FFF 0x00041FFE 0x x x value 0x14 0x45 0xDE 0x06 0x05 0x04 0x03 0x02 0x01 0x00 0x03 0x60 E 0xE0 0xA0 int *x = (int*)0x42000; cout << *x << endl; 0x = little endian (least significant byte has lowest address) 0x = big endian (most significant byte has lowest address) what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9 what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9

5 what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9 what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9 what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9 what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9

6 what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9 what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9 what s in those files? hello.c #include <stdio.h> int main(void) { puts("hello, World!"); urn 0; hello.o text (code) segment: 4 3 EC 0 BF E C0 4 3 C4 0 C3 data segment: C 6C 6F 2C F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symbol table: main text byte 0 hello.s.text main: sub $, mov $.Lstr, %rdi call puts xor %eax, %eax add $,.data.lstr:.string "Hello, World!" + stdio.o hello.exe (actually binary, but shown as hexadecimal) 4 3 EC 0 BF A E 0 4A C0 4 3 C4 0 C3 (code from stdio.o) C 6C 6F 2C F 72 6C 00 (data from stdio.o) 9 hello.s.lc0: main:.section.string "Hello, World!".text.globl main subq movl call movl addq $, $.LC0, %edi puts $0, %eax $,.rodata.str1.1,"ams",@progbi 10

7 hello.o hello.o: file format elf64-x6-64 pointer arithmetic read-only data 'H''e''l''l''o'' ''W''o''r''l''d''!''\0' SYMBOL TABLE: g F.text mai *UND* put RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE R_X6_64_32.rodata.str a R_X6_64_32 puts-0x hello + 0 0x4005C0 hello + 5 0x4005C5 * (hello + 0) is 'H' *(hello + 5) is ' ' hello[0] is 'H' hello[5] is ' ' Contents of section.text: ec0 bf e b00 H c40c3 H pointer arithmetic read-only data 'H''e''l''l''o'' ''W''o''r''l''d''!''\0' pointer arithmetic read-only data 'H''e''l''l''o'' ''W''o''r''l''d''!''\0' hello + 0 hello + 5 hello + 0 hello + 5 0x4005C0 0x4005C5 0x4005C0 0x4005C5 * (hello + 0) is 'H' *(hello + 5) is ' ' hello[0] is 'H' hello[5] is ' ' * (hello + 0) is 'H' *(hello + 5) is ' ' hello[0] is 'H' hello[5] is ' ' 12 12

8 some lists short sentinel = -9999; short *x; x = malloc(sizeof(short)*4); x[3] = sentinel; x x[0] x[1] x[2] x[3] some lists short sentinel = -9999; short *x; x = malloc(sizeof(short)*4); x[3] = sentinel; on stack or regs x on heap x[0] x[1] x[2] x[3] typedef struct range_t { unsigned int length; short *ptr; range; range x; x.length = 3; x.ptr = malloc(sizeof(short)*3); x len: 3 ptr: typedef struct range_t { unsigned int length; short *ptr; range; range x; x.length = 3; x.ptr = malloc(sizeof(short)*3); x len: 3 ptr: typedef struct node_t { short payload; list *next; node; node *x; x = malloc(sizeof(node_t)); x *x payload: 1 ptr: typedef struct node_t { short payload; list *next; node; node *x; x = malloc(sizeof(node_t)); x *x payload: 1 ptr: AT&T syntax in one slide AT&T syntax example (1) destination last () means value in memory disp(base, index, scale) same as memory[disp + base + index * scale] omit disp (defaults to 0) and/or omit base (defaults to 0) and/or scale (defualts to 1) $ means constant plain number/label means value in memory movq $42, (%rbx) // memory[rbx] 42 destination last ()s represent value in memory constants start with $ registers start with % q ( quad ) indicates length ( bytes) l: 4; w: 2; b: 1 sometimes can be omitted 14 15

9 AT&T syntax example (1) AT&T syntax example (1) movq $42, (%rbx) // memory[rbx] 42 destination last ()s represent value in memory constants start with $ registers start with % q ( quad ) indicates length ( bytes) l: 4; w: 2; b: 1 sometimes can be omitted 15 movq $42, (%rbx) // memory[rbx] 42 destination last ()s represent value in memory constants start with $ registers start with % q ( quad ) indicates length ( bytes) l: 4; w: 2; b: 1 sometimes can be omitted 15 AT&T syntax example (1) AT&T syntax example (1) movq $42, (%rbx) // memory[rbx] 42 destination last ()s represent value in memory constants start with $ registers start with % q ( quad ) indicates length ( bytes) l: 4; w: 2; b: 1 sometimes can be omitted 15 movq $42, (%rbx) // memory[rbx] 42 destination last ()s represent value in memory constants start with $ registers start with % q ( quad ) indicates length ( bytes) l: 4; w: 2; b: 1 sometimes can be omitted 15

10 closer look: condition codes (2) closer look: condition codes (3) // 2**63-1 movq $0x7FFFFFFFFFFFFFFF, %rax // 2**63 (unsigned); -2**63 (signed) movq $0x , %rbx cmpq %rax, %rbx // result = %rbx - %rax movq $ 1, %rax addq $ 2, %rax // result = -3 as signed: 1 + ( 2) = 3 as signed: 2 63 ( ) = (overflow) as unsigned: (2 64 1) + (2 64 2) = (overflow) as unsigned: 2 63 ( ) = 1 ZF = 0 (false) not zero rax and rbx not equal SF = 0 (false) not negative rax <= rbx (if correct) OF = 1 (true) overflow as signed incorrect for signed CF = 0 (false) no overflow as unsigned correct for unsigned 16 ZF = 0 (false) not zero result not zero SF = 1 (true) negative result is negative OF = 0 (false) no overflow as signed correct for signed CF = 1 (true) overflow as unsigned incorrect for unsigned 17 compiling switches (1) compiling switches (2) switch (a) { case 1: ; break; case 2: ; break; default: // same as if statement? cmpq $1, %rax je code_for_1 cmpq $2, %rax je code_for_2 cmpq $3, %rax je code_for_3 jmp code_for_default 1 switch (a) { case 1: ; break; case 2: ; break; case 100: ; break; default: // binary search cmpq $50, %rax jl code_for_less_than_50 cmpq $75, %rax jl code_for_50_to_75 code_for_less_than_50: cmpq $25, %rax jl less_than_25_cases 19

11 compiling switches (3) computed jumps switch (a) { case 1: ; break; case 2: ; break; case 100: ; break; default: // jump table cmpq $100, %rax jg code_for_default cmpq $1, %rax jl code_for_default jmp * table(,%rax,) table: // not instructions //.quad = 64-bit (4 x 16) constant.quad code_for_1.quad code_for_2.quad code_for_3.quad code_for_4 20 cmpq $100, %rax jg code_for_default cmpq $1, %rax jl code_for_default // jump to memory[table + rax * ] // table of pointers to instructions jmp * table(,%rax,) // intel: jmp QWORD PTR[rax* + table] table:.quad code_for_1.quad code_for_2.quad code_for_3 21 push/pop Y6-64 instruction formats pushq %rbx memory[] %rbx popq %rbx %rbx memory[] + stack growth. memory[ + 16] byte: halt 0 0 nop 1 0 rrmovq/cmovcc ra, rb 2 cc ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb D mrmovq D(rB), ra 5 0 ra rb D OPq ra, rb 6 fn ra rb jcc Dest 7 cc Dest memory[ + ] call Dest 0 Dest value to pop memory[] 9 0 where to push memory[ - ] memory[ - 16] pushq ra A 0 ra F popq ra B 0 ra F 22 23

12 Secondary opcodes: OPq Registers: ra, rb byte: halt 0 0 nop 1 0 rrmovq/cmovcc ra, rb 2 cc ra rb irmovq V, rb 3 0 F rb rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb OPq ra, rb 6 fn ra rb jcc Dest 7 cc call Dest pushq ra A 0 ra F popq ra B 0 ra F 0 add 1 sub Dest 2 and Dest 3 xor V D D byte: halt 0 0 nop 1 0 rrmovq/cmovcc ra, rb 2 cc ra rb irmovq V, rb 3 0 F rb rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb OPq ra, rb 6 fn ra rb jcc Dest 7 cc call Dest pushq ra A 0 ra F popq ra B 0 ra F 0 %rax %r 1 %rcx 9 %r9 2 %rdx A %r10 V 3 %rbx B %r11 D 4 D C %r12 5 %rbp D %r13 Dest 6 %rsi Dest E %r14 7 %rdi F none Immediates: V, D, Dest Immediates: V, D, Dest byte: byte: halt 0 0 halt 0 0 nop 1 0 nop 1 0 rrmovq/cmovcc ra, rb 2 cc ra rb irmovq V, rb 3 0 F rb rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb V D D rrmovq/cmovcc ra, rb 2 cc ra rb irmovq V, rb 3 0 F rb rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb V D D OPq ra, rb 6 fn ra rb jcc Dest 7 cc call Dest 0 Dest Dest OPq ra, rb 6 fn ra rb jcc Dest 7 cc call Dest 0 Dest Dest pushq ra A 0 ra F pushq ra A 0 ra F popq ra B 0 ra F popq ra B 0 ra F 26 26

13 bitwise strategies shift left use paper, find subproblems, etc. mask and shift (x & 0) >> 4 factor/distribute (x & 1) (y & 1) == (x y) & 1 x6 instruction: shl shift left shl $amount, %reg (or variable: shr %cl, %reg) %reg (initial value) divide and conquer common subexpression elimination urn ((!!x) & y) ((!x) & z) becomes d =!x; urn ((-!d) & y) ((-d) & z) %reg (final value) shift left x6 instruction: shl shift left shl $amount, %reg (or variable: shr %cl, %reg) %reg (initial value) left shift in math 1 << 0 == << 1 == << 2 == << 0 == << 1 == << 2 == %reg (final value)

14 left shift in math 1 << 0 == << 1 == << 2 == << 0 == << 1 == << 2 == logical right shift x6 instruction: shr logical shift right shr $amount, %reg (or variable: shr %cl, %reg) %reg (initial value) x << y = x 2 y %reg (final value) logical right shift logical right shift x6 instruction: shr logical shift right shr $amount, %reg (or variable: shr %cl, %reg) %reg (initial value) x6 instruction: shr logical shift right shr $amount, %reg (or variable: shr %cl, %reg) %reg (initial value) ???? %reg (final value) %reg (final value)

15 arithmetic right shift arithmetic right shift x6 instruction: sar arithmetic shift right sar $amount, %reg (or variable: sar %cl, %reg) x6 instruction: sar arithmetic shift right sar $amount, %reg (or variable: sar %cl, %reg) %reg (initial value) %reg (initial value) %reg (final value) %reg (final value) right shift in C registers int shift_signed(int x) { urn x >> 5; // arithmetic; fill w/ copies of unsigned shift_unsigned(unsigned x) { urn x >> 5; // logical; fill with zeroes shift_signed: movl %edi, %eax sarl $5, %eax shift_unsigned: movl %edi, %eax shrl $5, eax updates every clock cycle register output register input 32 33

16 state in Y6-64 state in Y6-64 l o g i c l o g i c logic R[] next R[] logic (with ALU) Data Stat l o g i c to to reg logic R[] next R[] logic (with ALU) Data Stat l o g i c to to reg state in Y6-64 state in Y6-64 l o g i c l o g i c logic R[] next R[] logic (with ALU) Data Stat l o g i c to to reg logic R[] next R[] logic (with ALU) Data Stat l o g i c to to reg 34 34

17 state in Y6-64 memories l o g i c address data logic R[] next R[] logic (with ALU) Data Stat l o g i c to to reg address input data output time memories memories address data input to write address write enable? Data data output read enable? address data input to write address write enable? Data data output read enable? address input data output time address input data output time address input input to write value in memory 35 35

18 read reg #s reg values read reg #s reg values write reg #s data to write %rax, %rdx, write reg #s data to write %rax, %rdx, register number input register value output time read reg #s reg values read reg #s reg values write reg #s data to write %rax, %rdx, write reg #s write register #15: write is ignoredread register #15: value is alway data to write %rax, %rdx, register number input register value output time register number input data input value in register register number input register value output time register number input data input value in register 36 36

19 ALUs SEQ circuit A B ALU operation select A OP B Operations needed: add addq, addresses sub subq xor xorq and andq more? valp + instr. length ra rb valc R[] next R[] ALU alua vale alub add/sub xor/and (function of instr.) Data in Data out Addr in write? function of opcode Stat 37 3 circuit: setting MUXes circuit: setting MUXes valc + 10 valc M[+2] instr. length ra rb R[] next R[] MUXes,,, alua, alub, dmemin Exercise: what do they select when running addq %r, %r9? 0 ALU alua vale alub add/sub xor/and (function of instr.) Data in Data out Addr in write? function of opcode M[+1] +2 + instr. length ra rb 9 ra= rb=9 next R[] R[] R[] R[9] 0 MUXes,,, alua, alub, dmemin Exercise: what do they select when running addq %r, %r9? ALU alua vale alub add/sub xor/and add (function of instr.) alua + alub Data in Data out Addr in write? function of opcode 39 39

20 circuit: setting MUXes circuit: setting MUXes valc M[+2] + 10 valc M[+2] + 10 M[+1] +2 + instr. length ra rb 9 ra= rb=9 next R[] R[] R[] R[9] 0 MUXes,,, alua, alub, dmemin Exercise: what do they select when running addq %r, %r9? ALU alua vale alub add/sub xor/and add (function of instr.) alua + alub Data in Data out Addr in write? function of opcode M[+1] +2 + instr. length ra rb 9 ra= rb=9 next R[] R[] R[] R[9] 0 ALU alua vale alub add/sub xor/and add (function of instr.) alua + alub Data in Data out Addr in write? function of opcode circuit: setting MUXes circuit: setting MUXes valc + 10 valc instr. length ra rb MUXes,,, alua, alub, dmemin Exercise: what do they select for rmmovq? R[] next R[] 0 ALU alua vale alub add/sub xor/and (function of instr.) Data in Data out Addr in write? function of opcode + instr. length MUXes,,, alua, alub, dmemin Exercise: what do they select for rmmovq? ra rb R[] next R[] 0 ALU alua vale alub add/sub xor/and (function of instr.) Data in Data out Addr in write? function of opcode 39 39

21 circuit: setting MUXes valc instr. length MUXes,,, alua, alub, dmemin Exercise: what do they select for call? ra rb R[] next R[] 0 ALU alua vale alub add/sub xor/and (function of instr.) Data in Data out Addr in write? function of opcode 39

layers of abstraction

layers of abstraction Exam Review 1 layers of abstraction 2 x += y Higher-level language: C add %rbx, %rax 60 03 SIXTEEN Assembly: X86-64 Machine code: Y86 Hardware Design Language: HCLRS Gates / Transistors / Wires / Registers

More information

bitwise (finish) / SEQ part 1

bitwise (finish) / SEQ part 1 bitwise (finish) / SEQ part 1 1 Changelog 1 Changes made in this version not seen in first lecture: 14 September 2017: slide 16-17: the x86 arithmetic shift instruction is sar, not sra last time 2 bitwise

More information

Changelog. Assembly (part 1) logistics note: lab due times. last time: C hodgepodge

Changelog. Assembly (part 1) logistics note: lab due times. last time: C hodgepodge Changelog Assembly (part 1) Corrections made in this version not seen in first lecture: 31 August 2017: slide 34: split out from previous slide; clarify zero/positive/negative 31 August 2017: slide 26:

More information

Corrections made in this version not seen in first lecture:

Corrections made in this version not seen in first lecture: Assembly (part 1) 1 Changelog 1 Corrections made in this version not seen in first lecture: 31 August 2017: slide 34: split out from previous slide; clarify zero/positive/negative 31 August 2017: slide

More information

CS 3330 Introduction 1

CS 3330 Introduction 1 CS 3330 Introduction 1 layers of abstraction 2 x += y Higher-level language: C add %rbx, %rax! 60 03 SIXTEEN Assembly: X86-64 Machine code: Y86 Hardware Design Language: HCLRS Gates / Transistors / Wires

More information

Changes made in this version not seen in first lecture:

Changes made in this version not seen in first lecture: bitwise operators 1 Changelog 1 Changes made in this version not seen in first lecture: 6 Feb 2018: arithmetic right shift: x86 arith. shift instruction is sar to sra 6 Feb 2018: logical left shift: use

More information

Brief Assembly Refresher

Brief Assembly Refresher Brief Assembly Refresher 1 Changelog 1 Changes made in this version not seen in first lecture: 23 Jan 2018: if-to-assembly if (...) goto needed b < 42 23 Jan 2018: caller/callee-saved: correct comment

More information

Changelog. Brief Assembly Refresher. a logistics note. last time

Changelog. Brief Assembly Refresher. a logistics note. last time Changelog Brief Assembly Refresher Changes made in this version not seen in first lecture: 23 Jan 2018: if-to-assembly if (...) goto needed b < 42 23 Jan 2018: caller/callee-saved: correct comment about

More information

SEQ part 3 / HCLRS 1

SEQ part 3 / HCLRS 1 SEQ part 3 / HCLRS 1 Changelog 1 Changes made in this version not seen in first lecture: 21 September 2017: data memory value MUX input for call is PC + 10, not PC 21 September 2017: slide 23: add input

More information

CSC 252: Computer Organization Spring 2018: Lecture 11

CSC 252: Computer Organization Spring 2018: Lecture 11 CSC 252: Computer Organization Spring 2018: Lecture 11 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Action Items: Assignment 3 is due March 2, midnight Announcement Programming

More information

Computer Organization: A Programmer's Perspective

Computer Organization: A Programmer's Perspective A Programmer's Perspective Instruction Set Architecture Gal A. Kaminka galk@cs.biu.ac.il Outline: CPU Design Background Instruction sets Logic design Sequential Implementation A simple, but not very fast

More information

Intel x86-64 and Y86-64 Instruction Set Architecture

Intel x86-64 and Y86-64 Instruction Set Architecture CSE 2421: Systems I Low-Level Programming and Computer Organization Intel x86-64 and Y86-64 Instruction Set Architecture Presentation J Read/Study: Bryant 3.1 3.5, 4.1 Gojko Babić 03-07-2018 Intel x86

More information

CS 3330: SEQ part September 2016

CS 3330: SEQ part September 2016 1 CS 3330: SEQ part 2 15 September 2016 Recall: Timing 2 compute new values between rising edges compute compute compute compute clock signal registers, memories change at rising edges next value register

More information

selected anonymous feedback: VM

selected anonymous feedback: VM Exam Review 1 selected anonymous feedback: VM 2 too few concrete examples of translation in lecture students were poorly prepared for memory HW holy hell, dont be giving us this memory hw and not give

More information

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

Computer Architecture I: Outline and Instruction Set Architecture. CENG331 - Computer Organization. Murat Manguoglu Computer Architecture I: Outline and Instruction Set Architecture CENG331 - Computer Organization Murat Manguoglu Adapted from slides of the textbook: http://csapp.cs.cmu.edu/ Outline Background Instruction

More information

selected anonymous feedback: VM Exam Review final format/content logistics

selected anonymous feedback: VM Exam Review final format/content logistics selected anonymous feedback: VM Exam Review too few concrete examples of translation in lecture students were poorly prepared for memory HW holy hell, dont be giving us this memory hw and not give us the

More information

cmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest

cmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest Instruction Set Architecture Computer Architecture: Instruction Set Architecture CSci 2021: Machine Architecture and Organization Lecture #16, February 24th, 2016 Your instructor: Stephen McCamant Based

More information

Areas for growth: I love feedback

Areas for growth: I love feedback Assembly part 2 1 Areas for growth: I love feedback Speed, I will go slower. Clarity. I will take time to explain everything on the slides. Feedback. I give more Kahoot questions and explain each answer.

More information

Topics of this Slideset. CS429: Computer Organization and Architecture. Instruction Set Architecture. Why Y86? Instruction Set Architecture

Topics of this Slideset. CS429: Computer Organization and Architecture. Instruction Set Architecture. Why Y86? Instruction Set Architecture Topics of this Slideset CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Intro to Assembly language Programmer visible state Y86

More information

Changelog. Changes made in this version not seen in first lecture: 13 Feb 2018: add slide on constants and width

Changelog. Changes made in this version not seen in first lecture: 13 Feb 2018: add slide on constants and width HCL 1 Changelog 1 Changes made in this version not seen in first lecture: 13 Feb 2018: add slide on constants and width simple ISA 4: mov-to-register 2 irmovq $constant, %ryy rrmovq %rxx, %ryy mrmovq 10(%rXX),

More information

last time Assembly part 2 / C part 1 condition codes reminder: quiz

last time Assembly part 2 / C part 1 condition codes reminder: quiz last time Assembly part 2 / C part 1 linking extras: different kinds of relocations addresses versus offset to addresses dynamic linking (briefly) AT&T syntax destination last O(B, I, S) B + I S + O jmp

More information

Lecture 3 CIS 341: COMPILERS

Lecture 3 CIS 341: COMPILERS Lecture 3 CIS 341: COMPILERS HW01: Hellocaml! Announcements is due tomorrow tonight at 11:59:59pm. HW02: X86lite Will be available soon look for an announcement on Piazza Pair-programming project Simulator

More information

CS 3330 Introduction. Daniel and Charles. CS 3330 Computer Architecture 1

CS 3330 Introduction. Daniel and Charles. CS 3330 Computer Architecture 1 CS 3330 Introduction Daniel and Charles CS 3330 Computer Architecture 1 lecturers Charles and I will be splitting lectures same(ish) lecture in each section Grading Take Home Quizzes: 10% (10% dropped)

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: October 11, 2017 at 17:42 CS429 Slideset 6: 1 Topics of this Slideset

More information

CS 3330 Exam 1 Fall 2017 Computing ID:

CS 3330 Exam 1 Fall 2017 Computing ID: S 3330 Fall 2017 xam 1 Variant page 1 of 8 mail I: S 3330 xam 1 Fall 2017 Name: omputing I: Letters go in the boxes unless otherwise specified (e.g., for 8 write not 8 ). Write Letters clearly: if we are

More information

last time more C / assembly intro anonymous feedback (2) anonymous feedback (1)

last time more C / assembly intro anonymous feedback (2) anonymous feedback (1) last time more C / assembly intro program memory layout stack versus heap versus code/globals at fixed locations (by convention only) compile/assemble/link object file machine code + data (from assembly)

More information

Instruc(on Set Architecture. Computer Architecture Instruc(on Set Architecture Y86. Y86-64 Processor State. Assembly Programmer s View

Instruc(on Set Architecture. Computer Architecture Instruc(on Set Architecture Y86. Y86-64 Processor State. Assembly Programmer s View Instruc(on Set Architecture Computer Architecture Instruc(on Set Architecture Y86 CSCI 2021: Machine Architecture and Organiza(on Pen- Chung Yew Department Computer Science and Engineering University of

More information

Computer Science 104:! Y86 & Single Cycle Processor Design!

Computer Science 104:! Y86 & Single Cycle Processor Design! Computer Science 104: Y86 & Single Cycle Processor Design Alvin R. Lebeck Slides based on those from Randy Bryant 1 CS:APP Administrative Homework #4 My office hours today 11:30-12:30 Reading: text 4.3

More information

Machine Language CS 3330 Samira Khan

Machine Language CS 3330 Samira Khan Machine Language CS 3330 Samira Khan University of Virginia Feb 2, 2017 AGENDA Logistics Review of Abstractions Machine Language 2 Logistics Feedback Not clear Hard to hear Use microphone Good feedback

More information

How Software Executes

How Software Executes How Software Executes CS-576 Systems Security Instructor: Georgios Portokalidis Overview Introduction Anatomy of a program Basic assembly Anatomy of function calls (and returns) Memory Safety Intel x86

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 7: Processor Architecture & Design John P. Shen & Gregory Kesden September 20, 2017 Lecture #7 Processor Architecture & Design Lecture #8 Pipelined Processor

More information

SEQ without stages. valc register file ALU. Stat ZF/SF. instr. length PC+9. R[srcA] R[srcB] srca srcb dstm dste. Data in Data out. Instr. Mem.

SEQ without stages. valc register file ALU. Stat ZF/SF. instr. length PC+9. R[srcA] R[srcB] srca srcb dstm dste. Data in Data out. Instr. Mem. Exam Review 1 SEQ without stages 2 0xF 0xF %rsp valc register file PC+9 PC + Instr. Mem. instr. length ra rb %rsp 0xF 0xF %rsp srca srcb dstm dste R[srcA] R[srcB] next R[dstM] next R[dstE] 0 8 ALU alua

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 5 LAST TIME Began exploring x86-64 instruction set architecture 16 general-purpose registers Also: All registers are 64 bits wide rax-rdx are

More information

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

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly II: Control Flow Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Processor State (x86-64) RAX 63 31 EAX 0 RBX EBX RCX RDX ECX EDX General-purpose

More information

Changelog. Changes made in this version not seen in first lecture: 12 September 2017: slide 28, 33: quote solution that uses z correctly

Changelog. Changes made in this version not seen in first lecture: 12 September 2017: slide 28, 33: quote solution that uses z correctly 1 Changelog 1 Changes made in this version not seen in first lecture: 12 September 2017: slide 28, 33: quote solution that uses z correctly last time 2 Y86 choices, encoding and decoding shift operators

More information

Recitation #6. Architecture Lab

Recitation #6. Architecture Lab 18-600 Recitation #6 Architecture Lab Overview Where we are Archlab Intro Optimizing a Y86 program Intro to HCL Optimizing Processor Design Where we Are Archlab Intro Part A: write and simulate Y86-64

More information

Do not turn the page until 5:10.

Do not turn the page until 5:10. University of Washington Computer Science & Engineering Autumn 2018 Instructor: Justin Hsia 2018-10-29 Last Name: First Name: Student ID Number: Name of person to your Left Right All work is my own. I

More information

Assembly II: Control Flow

Assembly II: Control Flow Assembly II: Control Flow Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)

More information

Pipelining 4 / Caches 1

Pipelining 4 / Caches 1 Pipelining 4 / Caches 1 1 2 after forwarding/prediction where do we still need to stall? memory output needed in fetch ret followed by anything memory output needed in exceute mrmovq or popq + use (in

More information

x86-64 Programming II

x86-64 Programming II x86-64 Programming II CSE 351 Winter 2018 Instructor: Mark Wyse Teaching Assistants: Kevin Bi Parker DeWilde Emily Furst Sarah House Waylon Huang Vinny Palaniappan http://xkcd.com/409/ Administrative Homework

More information

CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE351 Spring 2018, Midterm Exam April 27, 2018 CSE351 Spring 2018, Midterm Exam April 27, 2018 Please do not turn the page until 11:30. Last Name: First Name: Student ID Number: Name of person to your left: Name of person to your right: Signature indicating:

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr Bill Young Department of Computer Sciences University of Texas at Austin Last updated: March 15, 2018 at 10:58 CS429 Slideset 13: 1 The ISA Byte 0 1 2 3

More information

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Mechanisms in Procedures Passing control To beginning of procedure code

More information

Assembly Programming III

Assembly Programming III Assembly Programming III CSE 410 Winter 2017 Instructor: Justin Hsia Teaching Assistants: Kathryn Chan, Kevin Bi, Ryan Wong, Waylon Huang, Xinyu Sui Facebook Stories puts a Snapchat clone above the News

More information

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012 6.172 Performance Engineering of Software Systems SPEED LIMIT PER ORDER OF 6.172 LECTURE 3 C to Assembly I-Ting Angelina Lee September 13, 2012 2012 Charles E. Leiserson and I-Ting Angelina Lee 1 Bugs

More information

How Software Executes

How Software Executes How Software Executes CS-576 Systems Security Instructor: Georgios Portokalidis Overview Introduction Anatomy of a program Basic assembly Anatomy of function calls (and returns) Memory Safety Programming

More information

Layers of Abstraction. CS 3330: More C. printf. Last time

Layers of Abstraction. CS 3330: More C. printf. Last time Layers of Abstraction CS 3330: More C 30 August 2016 x += y add %rbx, %rax 60 03 Higher-level language: C Assembly: X86-64 Machine code: Y86 (we ll talk later) Logic and Registers 1 2 Last time printf

More information

x86 Programming I CSE 351 Winter

x86 Programming I CSE 351 Winter x86 Programming I CSE 351 Winter 2017 http://xkcd.com/409/ Administrivia Lab 2 released! Da bomb! Go to section! No Luis OH Later this week 2 Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals

More information

x86 Programming II CSE 351 Winter

x86 Programming II CSE 351 Winter x86 Programming II CSE 351 Winter 2017 http://xkcd.com/1652/ Administrivia 2 Address Computation Instruction v leaq src, dst lea stands for load effective address src is address expression (any of the

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 12

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 12 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 12 CS24 MIDTERM Midterm format: 6 hour overall time limit, multiple sittings (If you are focused on midterm, clock should be running.) Open book

More information

Where We Are. Optimizations. Assembly code. generation. Lexical, Syntax, and Semantic Analysis IR Generation. Low-level IR code.

Where We Are. Optimizations. Assembly code. generation. Lexical, Syntax, and Semantic Analysis IR Generation. Low-level IR code. Where We Are Source code if (b == 0) a = b; Low-level IR code Optimized Low-level IR code Assembly code cmp $0,%rcx cmovz %rax,%rdx Lexical, Syntax, and Semantic Analysis IR Generation Optimizations Assembly

More information

Computer Organization Chapter 4. Prof. Qi Tian Fall 2013

Computer Organization Chapter 4. Prof. Qi Tian Fall 2013 Computer Organization Chapter 4 Prof. Qi Tian Fall 2013 1 Topics Dec. 6 (Friday) Final Exam Review Record Check Dec. 4 (Wednesday) 5 variable Karnaugh Map Quiz 5 Dec. 2 (Monday) 3, 4 variables Karnaugh

More information

x64 Cheat Sheet Fall 2014

x64 Cheat Sheet Fall 2014 CS 33 Intro Computer Systems Doeppner x64 Cheat Sheet Fall 2014 1 x64 Registers x64 assembly code uses sixteen 64-bit registers. Additionally, the lower bytes of some of these registers may be accessed

More information

last time arrays versus pointers left shift arithmetic and logical left/right shift versus multiply/divide by power of two bitwise and/or/xor

last time arrays versus pointers left shift arithmetic and logical left/right shift versus multiply/divide by power of two bitwise and/or/xor 1 last time 2 arrays versus pointers left shift arithmetic and logical left/right shift versus multiply/divide by power of two bitwise and/or/xor topics today 3 some other C details interlude: using the

More information

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor CS 261 Fall 2018 0000000100000f50 55 48 89 e5 48 83 ec 10 48 8d 3d 3b 00 00 00 c7 0000000100000f60 45 fc 00 00 00 00 b0 00 e8 0d 00 00 00 31 c9 89 0000000100000f70 45 f8 89 c8 48 83 c4 10 5d c3 Mike Lam,

More information

Machine Program: Procedure. Zhaoguo Wang

Machine Program: Procedure. Zhaoguo Wang Machine Program: Procedure Zhaoguo Wang Requirements of procedure calls? P() { y = Q(x); y++; 1. Passing control int Q(int i) { int t, z; return z; Requirements of procedure calls? P() { y = Q(x); y++;

More information

Instructions and Instruction Set Architecture

Instructions and Instruction Set Architecture Chapter 2 Instructions and Instruction Set Architecture In this lecture, we study computer instructions and instruction set architecture by using assembly language programming. We will study x86-64 architecture

More information

cmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb D mrmovq D(rB), ra 5 0 ra rb D OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest

cmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb D mrmovq D(rB), ra 5 0 ra rb D OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest Computer Architecture: Y86-64 Sequential Implementation CSci 2021: Machine Architecture and Organization Lecture #19, March 4th, 2016 Your instructor: Stephen McCamant Based on slides originally by: Randy

More information

CSC 252: Computer Organization Spring 2018: Lecture 6

CSC 252: Computer Organization Spring 2018: Lecture 6 CSC 252: Computer Organization Spring 2018: Lecture 6 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Action Items: Assignment 2 is out Announcement Programming Assignment

More information

Process Layout and Function Calls

Process Layout and Function Calls Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized

More information

Assembly Language II: Addressing Modes & Control Flow

Assembly Language II: Addressing Modes & Control Flow Assembly Language II: Addressing Modes & Control Flow Learning Objectives Interpret different modes of addressing in x86 assembly Move data seamlessly between registers and memory Map data structures in

More information

Computer Science 104:! Y86 & Single Cycle Processor Design!

Computer Science 104:! Y86 & Single Cycle Processor Design! Computer Science 104:! Y86 & Single Cycle Processor Design! Alvin R. Lebeck! Slides based on those from Randy Bryant 1! CS:APP! CS:APP! Administrative! 2! CS:APP! Instruction Set Architecture! Application!

More information

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

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls Princeton University Computer Science 217: Introduction to Programming Systems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems x86-64 solutions Pertinent

More information

Overview. CS429: Computer Organization and Architecture. Y86 Instruction Set. Building Blocks

Overview. CS429: Computer Organization and Architecture. Y86 Instruction Set. Building Blocks Overview CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: March 15, 2018 at 10:54 How do we build a digital computer?

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers x86-64 Lite for Compiler Writers A quick (a) introduction or (b) review [pick one] Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 J-1 Administrivia HW3 due tonight At most 1

More information

cmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb D mrmovq D(rB), ra 5 0 ra rb D OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest

cmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb D mrmovq D(rB), ra 5 0 ra rb D OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest Computer Architecture: Y86-64 Sequential Implementation CSci 2021: Machine Architecture and Organization October 31st, 2018 Your instructor: Stephen McCamant Based on slides originally by: Randy Bryant

More information

Layers of Abstraction

Layers of Abstraction More C 1 Layers of Abstraction 2 x += y Higher-level language: C add %rbx, %rax 60 03 Assembly: X86-64 Machine code: Y86 (we ll talk later) Logic and Registers selected anonymous feedback (1) 3 If I finish

More information

Credits and Disclaimers

Credits and Disclaimers Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 3 nd Edition by Bryant and O'Hallaron

More information

x86 64 Programming II

x86 64 Programming II x86 64 Programming II CSE 351 Autumn 2018 Instructor: Justin Hsia Teaching Assistants: Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie

More information

CSE 351 Midterm Exam

CSE 351 Midterm Exam University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse February 5, 2018 CSE 351 Midterm Exam Last Name: First Name: SOLUTIONS UW Student ID Number: UW NetID (username):

More information

CSE 351 Midterm Exam Spring 2016 May 2, 2015

CSE 351 Midterm Exam Spring 2016 May 2, 2015 Name: CSE 351 Midterm Exam Spring 2016 May 2, 2015 UWNetID: Solution Please do not turn the page until 11:30. Instructions The exam is closed book, closed notes (no calculators, no mobile phones, no laptops,

More information

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

CS 261 Fall Mike Lam, Professor. x86-64 Control Flow CS 261 Fall 2018 Mike Lam, Professor x86-64 Control Flow Topics Condition codes Jumps Conditional moves Jump tables Motivation We cannot translate the following C function to assembly, using only data

More information

Machine-Level Programming (2)

Machine-Level Programming (2) Machine-Level Programming (2) Yanqiao ZHU Introduction to Computer Systems Project Future (Fall 2017) Google Camp, Tongji University Outline Control Condition Codes Conditional Branches and Conditional

More information

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

Control flow (1) Condition codes Conditional and unconditional jumps Loops Conditional moves Switch statements Control flow (1) Condition codes Conditional and unconditional jumps Loops Conditional moves Switch statements 1 Conditionals and Control Flow Two key pieces 1. Comparisons and tests: check conditions

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 26, 2018 at 12:02 CS429 Slideset 8: 1 Controlling Program

More information

Layers of Abstraction CS 3330: C. Compilation Steps. What s in those files? Higher-level language: C. Assembly: X86-64.

Layers of Abstraction CS 3330: C. Compilation Steps. What s in those files? Higher-level language: C. Assembly: X86-64. Layers of Abstraction CS 3330: C 25 August 2016 x += y add %rbx, %rax 60 03 Higher-level language: C Assembly: X86-64 Machine code: Y86 (we ll talk later) Logic and Registers 1 2 Compilation Steps compile:

More information

Computer Architecture and System Programming Laboratory. TA Session 3

Computer Architecture and System Programming Laboratory. TA Session 3 Computer Architecture and System Programming Laboratory TA Session 3 Stack - LIFO word-size data structure STACK is temporary storage memory area register points on top of stack (by default, it is highest

More information

CSCI 2021: x86-64 Control Flow

CSCI 2021: x86-64 Control Flow CSCI 2021: x86-64 Control Flow Chris Kauffman Last Updated: Mon Mar 11 11:54:06 CDT 2019 1 Logistics Reading Bryant/O Hallaron Ch 3.6: Control Flow Ch 3.7: Procedure calls Goals Jumps and Control flow

More information

Where Have We Been? Logic Design in HCL. Assembly Language Instruction Set Architecture (Y86) Finite State Machines

Where Have We Been? Logic Design in HCL. Assembly Language Instruction Set Architecture (Y86) Finite State Machines Where Have We Been? Assembly Language Instruction Set Architecture (Y86) Finite State Machines States and Transitions Events Where Are We Going? Tracing Instructions at the Register Level Build a CPU!

More information

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

L09: Assembly Programming III. Assembly Programming III. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson Assembly Programming III CSE 351 Spring 2017 Guest Lecturer: Justin Hsia Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis

More information

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Basic Execution Environment RAX RBX RCX RDX RSI RDI RBP RSP R8 R9 R10

More information

C++ to assembly to machine code

C++ to assembly to machine code IBCM 1 C++ to assembly to machine code hello.cpp #include int main() { std::cout

More information

minor HCL update Pipe Hazards (finish) / Caching post-quiz Q1 B post-quiz Q1 D new version of hclrs.tar:

minor HCL update Pipe Hazards (finish) / Caching post-quiz Q1 B post-quiz Q1 D new version of hclrs.tar: minor HCL update Pipe Hazards (finish) / Caching new version of hclrs.tar: removes poptest.yo from list of tests for seqhw, pipehw2 gives error if you try to assign to register output: register xy { foo

More information

6.1. CS356 Unit 6. x86 Procedures Basic Stack Frames

6.1. CS356 Unit 6. x86 Procedures Basic Stack Frames 6.1 CS356 Unit 6 x86 Procedures Basic Stack Frames 6.2 Review of Program Counter (Instruc. Pointer) PC/IP is used to fetch an instruction PC/IP contains the address of the next instruction The value in

More information

Pipelining 3: Hazards/Forwarding/Prediction

Pipelining 3: Hazards/Forwarding/Prediction Pipelining 3: Hazards/Forwarding/Prediction 1 pipeline stages 2 fetch instruction memory, most PC computation decode reading register file execute computation, condition code read/write memory memory read/write

More information

CS 3330 Exam 2 Spring 2017 Name: EXAM KEY Computing ID: KEY

CS 3330 Exam 2 Spring 2017 Name: EXAM KEY Computing ID: KEY S 3330 Spring 2017 Exam 2 Variant E page 1 of 6 Email I: KEY S 3330 Exam 2 Spring 2017 Name: EXM KEY omputing I: KEY Letters go in the boxes unless otherwise specified (e.g., for 8 write not 8 ). Write

More information

Machine-Level Programming II: Control

Machine-Level Programming II: Control Machine-Level Programming II: Control CSE 238/2038/2138: Systems Programming Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O Hallaron s slides 1 Today Control: Condition codes Conditional

More information

Machine-Level Programming II: Control

Machine-Level Programming II: Control Mellon Machine-Level Programming II: Control CS140 Computer Organization and Assembly Slides Courtesy of: Randal E. Bryant and David R. O Hallaron 1 First https://www.youtube.com/watch?v=ivuu8jobb1q 2

More information

Question Points Score Total: 100

Question Points Score Total: 100 Computer Science 2021 Spring 2016 Midterm Exam 1 February 29th, 2016 Time Limit: 50 minutes, 3:35pm-4:25pm This exam contains 7 pages (including this cover page) and 5 questions. Once we tell you to start,

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 4 LAST TIME Enhanced our processor design in several ways Added branching support Allows programs where work is proportional to the input values

More information

Do not turn the page until 11:30.

Do not turn the page until 11:30. University of Washington Computer Science & Engineering Autumn 2016 Instructor: Justin Hsia 2016-11-02 Last Name: First Name: Perfect Perry Student ID Number: 1234567 Section you attend (circle): Chris

More information

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

C to Machine Code x86 basics: Registers Data movement instructions Memory addressing modes Arithmetic instructions C to Machine Code x86 basics: Registers Data movement instructions Memory addressing modes Arithmetic instructions Program, Application Software Hardware next few weeks Programming Language Compiler/Interpreter

More information

Background: Sequential processor design. Computer Architecture and Systems Programming , Herbstsemester 2013 Timothy Roscoe

Background: Sequential processor design. Computer Architecture and Systems Programming , Herbstsemester 2013 Timothy Roscoe Background: Sequential processor design Computer Architecture and Systems Programming 252 0061 00, Herbstsemester 2013 Timothy Roscoe Overview Y86 instruction set architecture Processor state Instruction

More information

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

%r8 %r8d. %r9 %r9d. %r10 %r10d. %r11 %r11d. %r12 %r12d. %r13 %r13d. %r14 %r14d %rbp. %r15 %r15d. Sean Barker Procedure Call Registers Return %rax %eax %r8 %r8d Arg 5 %rbx %ebx %r9 %r9d Arg 6 Arg 4 %rcx %ecx %r10 %r10d Arg 3 %rdx %edx %r11 %r11d Arg 2 %rsi %esi %r12 %r12d Arg 1 %rdi %edi %r13 %r13d ptr %esp %r14

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College February 9, 2016 Reading Quiz Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between

More information

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

Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved. Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved. Anyone is free to download and print the PDF edition of this book for personal use. Commercial distribution,

More information

Computer Science 104:! Y86 & Single Cycle Processor Design!

Computer Science 104:! Y86 & Single Cycle Processor Design! Computer Science 104: Y86 & Single Cycle Processor Design Alvin R. Lebeck Slides based on those from Randy Bryant CS:APP Administrative HW #4 Due tomorrow tonight HW #5 up soon ing: 4.1-4.3 Today Review

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 21: Generating Pentium Code 10 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Simple Code Generation Three-address code makes it

More information

CS 3330 Exam 3 Fall 2017 Computing ID:

CS 3330 Exam 3 Fall 2017 Computing ID: S 3330 Fall 2017 Exam 3 Variant E page 1 of 16 Email I: S 3330 Exam 3 Fall 2017 Name: omputing I: Letters go in the boxes unless otherwise specified (e.g., for 8 write not 8 ). Write Letters clearly: if

More information

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

X86 Addressing Modes Chapter 3 Review: Instructions to Recognize X86 Addressing Modes Chapter 3" Review: Instructions to Recognize" 1 Arithmetic Instructions (1)! Two Operand Instructions" ADD Dest, Src Dest = Dest + Src SUB Dest, Src Dest = Dest - Src MUL Dest, Src

More information