MIPS汇编语言备课讲稿.ppt
文本预览下载声明
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker MIPS Assembly Instructions add $t0, $t1, $t2 # $t0=$t1+$t2 sub $t0, $t1, $t2 # $t0=$t1-$t2 lw $t1, a_addr # $t1=Mem[a_addr] sw $s1, a_addr # Mem[a_addr]=$t1 Assembler directives .text assembly instructions follow .data data follows .globl globally visible label = symbolic address Addressing modes lw $s1, addr # load $s1 from addr lw $s1, 8($s0) # $s1 = Mem[$s0+8] register $s0 contains the base address access the address ($s0) possibly add an offset 8($s0) Load and move instructions la $a0, addr # load address addr into $a0 li $a0, 12 # load immediate $a0 = 12 lb $a0, c($s1) # load byte $a0 = Mem[$s1+c] lh $a0, c($s1) # load half word lw $a0, c($s1) # load word move $s0, $s1 # $s0 = $s1 Control Structures Assembly language has very few control structures: Branch instructions if cond then goto label Jump instructions goto label We can build while loops, for loops, repeat-until loops, if-then-else structures from these primitives Branch instructions beqz $s0, label if $s0==0 goto label bnez $s0, label if $s0!=0 goto label bge $s0, $s1, label if $s0=$s1 goto label ble $s0, $s1, label if $s0=$s1 goto label blt $s0, $s1, label if $s0$s1 goto label beq $s0, $s1, label if $s0==$s1 goto label bgez $s0, $s1, label if $s0=0 goto label if-then-else structures if ($t0==$t1) then /* blockA */ else /* blockB */ beq $t0, $t1, blockA j blockB blockA: … instructions of then block … j exit blockB: … instructions of else block … exit: … subsequent instructions … repeat-until loop repeat … until $t0$t1 loop: … instructions of loop … ble $t0, $t1, loop # if $t0=$t1 goto loop Other loop structures are similar… Exercise: Derive templates for various loop structures System calls load argument registers load call code syscall li $a0, 10 # load argument $a0=10 li $v0, 1 # call code to print integer syscall #
显示全部