the mystery of the computer programmable computer
play

The mystery of the computer programmable computer 10101011110101 - PowerPoint PPT Presentation

01110111010110 11110101010101 00101011010011 01010111010101 01001010101010 10101010101010 The mystery of the computer programmable computer 10101011110101 Mikko Kivel 01010101011101 01010111010110 Department of Computer Science


  1. 01110111010110 11110101010101 00101011010011 01010111010101 01001010101010 10101010101010 The mystery of the computer –– programmable computer 10101011110101 Mikko Kivelä 01010101011101 01010111010110 Department of Computer Science 10101101010110 Aalto University 10101110101010 11101010101101 23 March 2020 01110111010110 10111011010101 Lecture notes based on material created by 11110101010101 Petteri Kaski 00010101010101 01011010101110 10101010100101

  2. 
 
 
 
 
 
 The mystery of the computer (4 rounds) –– binary numbers, 
 2. Bits and data 
 manipulating bits with Scala 3. Combinational logic 
 –– circuits built of logic gates simulated with Scala –– clock and feedback to the 4. Sequential logic 
 Scala simulation, processor data path –– assembly language 5. Programmable computer programming 
 Scala simulated “ armlet ” processor

  3. 5. Programmable computer

  4. What are the principles of how computers operate? (sequential logic — round 4) How to build a programmable machine? What is computing?

  5. Building blocks for sequential logic ? NOT (wire) 0 1 AND (input elements) OR (clock triggered feedbacks) (logic gates)

  6. armlet data path lcu_e C $0 $1 $2 $3 $4 $5 $6 $7 Load completion unit read_in instr_in immed_in Instruction decoder unit Arithmetic logic unit mem_read_e mem_write_e mem_addr Memory interface unit mem_data lcu_e C $0 $1 $2 $3 $4 $5 $6 $7

  7. Instruction set (instructions configuring the data path) nop # no operation mov $L, $A # $L = $A (copy the value of $A to $L) and $L, $A, $B # $L = bitwise AND of $A and $B ior $L, $A, $B # $L = bitwise (inclusive) OR of $A and $B eor $L, $A, $B # $L = bitwise exclusive-OR of $A and $B not $L, $A # $L = bitwise NOT of $A add $L, $A, $B # $L = $A + $B sub $L, $A, $B # $L = $A - $B neg $L, $A # $L = -$A lsl $L, $A, $B # $L = $A shifted to the left by $B bits lsr $L, $A, $B # $L = $A shifted to the right by $B bits asr $L, $A, $B # $L = $A (arithmetically) shifted to the right by $B bits mov $L, I # $L = I (copy the immediate data I to $L) add $L, $A, I # $L = $A + I sub $L, $A, I # $L = $A - I and $L, $A, I # $L = bitwise AND of $A and I ior $L, $A, I # $L = bitwise (inclusive) OR of $A and I eor $L, $A, I # $L = bitwise exclusive OR of $A and I lsl $L, $A, I # $L = $A shifted to the left by I bits lsr $L, $A, I # $L = $A shifted to the right by I bits asr $L, $A, I # $L = $A (arithmetically) shifted to the right by I bits loa $L, $A # $L = [contents of memory word at address $A] sto $L, $A # [contents of memory word at address $L] = $A

  8. Representing instructions in binary (**) sub $2, $0, $1 0001000010000111 ior $7, $1, 12345 0000001111011100 0011000000111001

  9. Data path with the Trigger tool [demo] import armlet._ new DataPathTrigger ()

  10. Data path executes given instructions one by one –– What about programmability ? What is missing?

  11. Scala example from the first lecture def test(m : Long) = { var i = 1L var s = 0L while (i <= m) { // s = 1 + 2 + ... + m s = s + i i = i + 1 } s } val NANOS_PER_SEC = 1e9 val test_start_time = System .nanoTime test(4000000000L) val test_end_time = System .nanoTime val test_duration = test_end_time - test_start_time println("test took %.2f seconds".format(test_duration/ NANOS_PER_SEC ))

  12. [demo]

  13. Program = a sequence of instructions in the memory 00000: 0000000000011010 00001: 0000000000001010 00002: 0000000001011010 00003: 0000000000000001 00004: 0000000010011010 00005: 0000000000000000 00006: 0000000000100011 00007: 0000000000000000 00008: 0000000000100101 00009: 0000000000010001 00010: 0001010010000110 00011: 0000001001011110 00012: 0000000000000001 00013: 0000000000011111 00014: 0000000000000001 00015: 0000000000100100 00016: 0000000000000110 00017: 0000000000111111 Machine executes the program, one instruction at a time, automatically

  14. How to make the execution automatic? (using the tools of sequential logic)

  15. What is execution?

  16. 1) Load instructions from memory, one at a time, and 2) Direct the instruction to the data path

  17. Is this all?

  18. Instructions are loaded from the memory, “one at a time” But in which order? Where exactly do we get the next instruction?

  19. Program Counter (PC) = register which at time t tells where the execution of the program is at (= from which memory address the instruction executed at time t was loaded)

  20. Increasing the program counter • By default: PC t + 1 = PC t + 1 (start: PC 0 = 0) • The default order can be altered with instructions controlling the flow of execution: • Jump instructions • PC t + 1 = a target address • Branch instructions (“branch”) • PC t + 1 = a target address 
 if branching condition is true; 
 otherwise default order (PC t + 1)

  21. Program Status Register (PSR) = register, where the result of the latest comparison instruction is saved (branching instructions use the result to control the flow of execution)

  22. Jump • A jump instructs to continue the program execution at a target address • In practise: jump moves the target address to the program counter register (similar to a mov instruction) jmp >target # jump to label @target # ... some code here ... @target: # ... some further code here ...

  23. Comparison + Branching • Compare two values 
 (register vs register or register vs constant) • Conditional branching based on the latest comparison result • Jump is executed if and only if branching condition is true • Otherwise continue executing in the default order cmp $7, 0 # compare $7 (left) and 0 (right) beq >done # jump to label @done if left == right # ... some code here ... @done: # ... some further code here ...

  24. Armlet processor (*) PC PS lcu_e C $0 $1 $2 $3 $4 $5 $6 $7 Load completion unit read_in reset_e Control and execution unit Arithmetic logic unit mem_read_e mem_write_e mem_addr Memory interface unit hlt_f mem_data PC PS lcu_e C $0 $1 $2 $3 $4 $5 $6 $7

  25. Round 5: Programmable computer • Instructions controlling the flow of execution 
 (jump and conditional branching) • Machine code (binary) and 
 symbolic machine code (“assembly language”) • Symbolic machine code programming • Machine code programming and simulation environment “ armlet ” architecture (“ Ticker ” tool)

  26. Instruction set (Instruction controlling the flow of execution) Comparison cmp $A, $B # compare $A (left) and $B (right) cmp $A, I # compare $A (left) and I (right) jmp $A # jump to address $A beq $A # ... if left == right (in the most recent comparison) Jump and bne $A # ... if left != right branch based bgt $A # ... if left > right (signed) on the results blt $A # ... if left < right (signed) bge $A # ... if left >= right (signed) of the latest ble $A # ... if left <= right (signed) comparison bab $A # ... if left > right (unsigned) bbw $A # ... if left < right (unsigned) bae $A # ... if left >= right (unsigned) bbe $A # ... if left <= right (unsigned) jmp I # jump to address I beq I # ... if left == right (in the most recent comparison) Jump and bne I # ... if left != right bgt I # ... if left > right (signed) branch based blt I # ... if left < right (signed) on the results bge I # ... if left >= right (signed) of the latest ble I # ... if left <= right (signed) bab I # ... if left > right (unsigned) comparison bbw I # ... if left < right (unsigned) bae I # ... if left >= right (unsigned) bbe I # ... if left <= right (unsigned) hlt # halt execution Halt trp # trap (break out of execution for debugging)

  27. Our first armlet program var t = 10 var i = 1 var s = 0 while (t != 0) { s = s + i i = i + 1 t = t - 1 }

  28. Symbolic armlet Machine language program machine language ( armlet -binary ) program 00000: 0000000000011010 00001: 0000000000001010 00002: 0000000001011010 mov $0, 10 00003: 0000000000000001 mov $1, 1 00004: 0000000010011010 mov $2, 0 00005: 0000000000000000 @loop: 00006: 0000000000100011 cmp $0, 0 00007: 0000000000000000 beq >done 00008: 0000000000100101 add $2, $2, $1 00009: 0000000000010001 add $1, $1, 1 00010: 0001010010000110 sub $0, $0, 1 Machine code 00011: 0000001001011110 jmp >loop 00012: 0000000000000001 @done: compiler 00013: 0000000000011111 hlt 00014: 0000000000000001 00015: 0000000000100100 = Assembler 00016: 0000000000000110 00017: 0000000000111111 Assembly-language (Loadable/executable) 
 armlet binary program

  29. Examples in the reading material • Sum of the data in an array • Maximum value in an array • Sorting an array • Using the stack when you run out of registers

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend