代写代考 CSE12 Assembly

CSE12 Assembly

Annoucements
• Midterm grades

Copyright By PowCoder代写 加微信 powcoder

•quiz RISC-V
• Lab3 out
Prof. Renau

Last (prev-midterm) class
•5- Model with RISC-V (3+ days) •5.1-Intro generic RISC-V machine
http://tice.sea.eseo.fr/riscv/
•5.2-Representing RISC-V instructions (COD 2.5) •5.3-RISC-V arithmetic instructions
Encoding + emulsiV •5.4-RISC-V memory instructions
Encoding + emulsiV
•5.5-RISC-V control flow instructions (COD 2.7)
Encoding + emulsiV
CMPE 110 Prof. Renau

•Basic programming constructs
•sequence statements • if/else
Prof. Renau

Flowchart Blocks
CMPE 110 Prof. Renau

Sequential Block Examples
money = money + 3
// memory declaration
money @ 0x50
// x2 address for money
// x3 money contents
addi x2, x0, 80
lw x3, 0(x2)
addi x3, x3, 3
sw x3, 0(x2)
Prof. Renau

Sequential Block Examples
money = money + 3
money = money – gift
// memory declaration
money @ 0x50
gift @ 0x54
// x2 address for money
// x3 money contents
// x4 address for gift
// x5 gift contents
addi x2, x2, 80
lw x3, 0(x2)
addi x3, x3, 3
addi x4, x0, 84
lw x5, 0(x4)
sub x3, x3, x5
sw x3, 0(x2)
Prof. Renau

Sequential Block Examples
money = money + 3
money = money – gift
// memory declaration
money @ 0x5010
gift @ 0x54
// x2 address for money
// x3 money contents
// x4 address for gift
// x5 gift contents
lui x2, 20480 // 0x5000
addi x2, x2, 16// 0x0010
lw x3, 0(x2)
addi x3, x3, 3
addi x4, x0, 84
lw x5, 0(x4)
sub x3, x3, x5
sw x3, 0(x2)
Prof. Renau

Remove Redundance Sequential Blocks
money = money + 3
money = money – gift
// memory declaration
money @ 0x500
gift @ 0x504
Prof. Renau

Share notes and comments with the people next to you. You can prepare a question for the end of the break.
2 MINUTE THINKING BREAK
CMPE 110 Prof. Renau

• Sequential Blocks • IF/ELSE
• While loops
• Do while loops
• For loops
Basic Structures
Prof. Renau

IF/ELSE Structure
if condition
taken_stmts
not_taken_stmts
TF condition
taken_stmts
not_taken_stmts
Prof. Renau

IF/ELSE Example
money=money+3 money=money-1
if money > 30
money = money – 1
money = money + 3
Prof. Renau

IF/ELSE Translation
Money>30? money=money+3 money=money-1
if money > 30
money = money – 1
money = money + 3
b?? goelse_label
// money = money – 1
jal x0, doneif_label
goelse_label:
// money = money + 3
doneif_label:
Prof. Renau

IF/ELSE Assembly
Money>30? money=money+3 money=money-1
b?? goelse_label
// money = money – 1
jal x0, doneif_label
goelse_label:
// money = money + 3
doneif_label:
// x3 address for money
// x10 money contents
lw x10, 0(x3)
addi x2, x0, 30
blt x10, x2, 12
addi x10, x10, -1
addi x10, x10, 3
sw x10, 0(x3)
Prof. Renau

Share notes and comments with the people next to you. You can prepare a question for the end of the break.
2 MINUTE THINKING BREAK
CMPE 110 Prof. Renau

While Loop Structure
T loop_body
while test
Prof. Renau

while money > 20
interest = interest + 1
money = money-interest
T loop_body
While Loop Example
Prof. Renau

while money > 20
interest = interest + 1
doloop: // Perform condition check b?? x??,x?? L1_done // money <= 20 // interest = interest + 1 // money = money-interest jal x0, doloop = money-interest While Loop Translation Prof. Renau while money > 20
interest = interest + 1
money = money-interest
// interest @ 0x54
// money @ 0x50
// x3 address for money
// x10 money contents
// x4 addr interest
addi x2, x0, 20
lw x10, 0(x3)
bge x2, x10, 28 // 20>=m
lw x5, 4(x3)
addi x5, x5, 1
sw x5, 4(x3)
sub x10, x10, x5
sw x10, 0(x3)
jal x0, -24
doloop: // Perform condition check b?? x??,x?? L1_done_label
// interest = interest + 1
// money = money-interest
jal x0, doloop
L1_done_label:
While Loop Assembly
Prof. Renau

// Sum integers from 1 to 100
while count <= 100 sum = sum + count Pseudo-Code Prof. Renau Share notes and comments with the people next to you. You can prepare a question for the end of the break. 2 MINUTE THINKING BREAK CMPE 110 Prof. Renau while condition total = 1000 sum =0 total = total + 1 sum = sum + 1 while total < 100 Do While Loop Structure Prof. Renau Share notes and comments with the people next to you. You can prepare a question for the end of the break. 2 MINUTE THINKING BREAK CMPE 110 Prof. Renau T loop_body For Loop Structure for init ; test ; re-init Prof. Renau for i=0 to 100 money = money + i for i=0 ; i<100 ; i++ money = money + i T loop_body For Loop Example Prof. Renau for i=0 to 100 money = money + i // init: i=0 doloop: // Perform condition check b?? x??, x??, L1_done_label // money = money + i // step: i=i+1 jal x0, doloop L1_done_label: For Loop Translation Prof. Renau Share notes and comments with the people next to you. You can prepare a question for the end of the break. 2 MINUTE THINKING BREAK CMPE 110 Prof. Renau for i=0 to 100 if money > 44
money = money + 2
foo = foo + 3
Nesting Constructs Translation
Prof. Renau

Nesting Constructs Translation
for i=0 to 100
if money > 44
money = money + 2
foo = foo + 3
// init: i = 0
doloop:// Perform condition check
b?? x?, x?, loop_done
b?? x?, x?, goelse_label // money = money + 2 jal x0, doneif_label
goelse_label:
// foo = foo + 3
doneif_label:
// step: i = i + 1
jal x0, doloop
loop_done:
Prof. Renau

•WEEK 7-8 •Code snippets
CMPE 110 Prof. Renau

•6-Assembly vs C Programming (3+ days) •6.1-compiling RISC-V baremetal •6.2-Assembly directives
•6.3-C-if in assembly
Next Class
Prof. Renau

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com