250 likes | 596 Views
컴퓨터의 개념과 실습. Assembly Example. Python vs. Assembly. Python. Assembly. f = (g + h) – ( i + j ). ADD R5, R1, R2 ADD R6, R3, R4 SUB R0, R5, R6. f is mapped to R0 g is mapped to R1 h is mapped to R2 i is mapped to R3 j is mapped to R4. Python vs. Assembly. Python.
E N D
컴퓨터의 개념과 실습 Assembly Example
Python vs. Assembly Python Assembly f = (g + h) – (i + j) ADD R5, R1, R2 ADD R6, R3, R4 SUB R0, R5, R6 f is mapped to R0 g is mapped to R1 h is mapped to R2 iis mapped to R3 j is mapped to R4
Python vs. Assembly Python Assembly g = h + A[i] ADD R4, R2, R3 LDR R5, [R4] ADD R0, R1, R5 g is mapped to R0 h is mapped to R1 R2 contains the base address of array A[]. iis mapped to R3.
Python vs. Assembly Python Assembly if (i == j): f = g + h else: f = g – h CMP R3, R4 BNE ELSE ADD R0, R1, R2 B EXIT ELSE: SUB R0, R1, R2 EXIT: f is mapped to R0 g is mapped to R1 h is mapped to R2 iis mapped to R3 j is mapped to R4
Python vs. Assembly Python Assembly while (save[i] == k): i = i + j LOOP: ADD R4, R0, R3 LDR R5, [R4] CMP R2, R5 BNE EXIT ADD R0, R0, R1 B LOOP EXIT: iis mapped to R0 j is mapped to R1 k is mapped to R2 R3 contains the base address of array save[].
Example Assembly Code & ISA Register Memory <Python> sum = 0 list = [11, 13, 16] for i in range(0,3): sum = sum + list[i] <Assembly> MOV R0, #0 MOV R2, #6 L: ADD R2, R2, #1 LDR R1, [R2] ADD R0, R0, R1 CMP R2, #9 BNE L MOV R2, #10 STR R0, [R2] <R egister & Memory>
Instruction Set Architecture Register Memory Register Memory MOV R0, #0 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory MOV R2, #6 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory ADD R2, R2, #1 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory LDR R1, [R2] • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory ADD R0, R0, R1 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory CMP R2, #9 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory BNE L • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory ADD R2, R2, #1 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory LDR R1, [R2] • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory ADD R0, R0, R1 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory CMP R2, #9 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory BNE L • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory ADD R2, R2, #1 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory LDR R1, [R2] • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory ADD R0, R0, R1 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory CMP R2, #9 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory BNE L • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory MOV R2, #10 • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory
Instruction Set Architecture Register Memory Register Memory STR R0, [R2] • Assumptions • 32bit ISA • # of registers = 8 + PC (Program Counter) + PSR (Program Status Register) • Memory size = 176KB Before Register and Memory After Register and Memory