Microsoft Word Huong dan thuc hanh mips asm tren pcspim doc



tải về 0.57 Mb.
Chế độ xem pdf
trang6/10
Chuyển đổi dữ liệu02.11.2023
Kích0.57 Mb.
#55526
1   2   3   4   5   6   7   8   9   10
huong dan thuc hanh mips asm tren pcspim 5652
MIPSSSS, 5
5.6 Các lệnh mã giả mở rộng 
Thiết lập các tham số trong menu Simulator -> Settings: 
SPIM set Bare Machine OFF, Allow Pseudo Instructions ON, Load Trap File OFF, 
Delayed Branches ON, Delayed Loads ON, Mapped IO OFF, Quiet OFF.
Ví dụ theo sau thực hiện việc tính hóa đơn bữa ăn:
tổng phí = tiền thức ăn + 8% tiền thuế +15% tiền phục vụ 
.text 
.globl main 
main: lui $10,0x1000 # initialize base register of the string 
lbu $8,($10) # get the first char of the string 
sll $0,$0,0 
loop: 
beq $8,$0,halt # while ( char != '/0' ) 
sll $0,$0,0 # 
addiu $8,$8,0x20 # uncapitalize char 
sb $8,($10) # replace char in string 
addiu $10,$10,1 # advance the char pointer 
lbu $8,($10) # get the next char of the string 
j loop # end while 
sll $0,$0,0 
halt: j halt # cycle sponge 
sll $0,$0,0 
.data 
string: .asciiz "ABCDEFGHIJKLMNOP" 
## End of file 
move d,s
# copy the contents of the source register s to the 
# destination register d 
li d,value # load register $d with the positive or negative
# integer "value". Value may be a 16 or a 32-bit integer. 
lw d,exp # Load register $d with the value at address "exp".
# "exp" is often a symbolic address. 
la d,exp # load register $d with the address described by the
# expression "exp". "exp" is often a symbolic address. 
nop # no operation. do nothing for one machine cycle. 
sw d,exp # Store register $d into the word at address exp.
# exp can be any of several expression types
# that evaluate to an address 
mul d,s,t
# multiply $s by $t. put the result in $d 
div d,s,t
# divide $s by $t. Put the quotient in $d. Operands are 
# two's complement. 
divu d,s,t
# divide $s by $t. Put the quotient in $d. Operands are 
# unsigned. 
remu d,s,t
# divide $s by $t. Put the remainder in $d. Operands are 
# unsigned. 


## rest.asm 
## 
## Total restaurant bill calculator 
## 
## Register Use: 
## 
## $s0 meal cost
## $s1 tip rate 
## $s2 tax rate 
## $s3 total rate 
## $s4 tax+tip dollars 
## $s5 total bill 
.globl main 
# Get meal cost 
main: li $v0,4 # print prompt 
la $a0,prompt
syscall 
li $v0,5 # input meal cost 
syscall 
move $s0,$v0 # save it in $s0 
# Calculations 
lw $s1,tip # get tip rate 
lw $s2,tax # get tax rate 
addu $s3,$s1,$s2 # (tax + tip) in percent 
mul $s4,$s0,$s3 # mealcost*(total rate) 
div $s4,$s4,100 # mealcost*(total rate)/100
addu $s5,$s0,$s4 # total bill 
# Output 
li $v0,4 # print string 
la $a0,head1 # "tax plus tip" 
syscall 
move $a0,$s4 # get tax+tip 
li $v0,1 # print integer 
syscall #
li $v0,4 # print string 
la $a0,head2 # "total cost" 
syscall 
move $a0,$s5 # get total 
li $v0,1 # print integer 
syscall #
li $v0,10 # exit 
syscall 
.data 
tip: .word 15 # tip rate in percent 
tax: .word 8 # tax rate in percent 
prompt: .asciiz "Enter food cost: " 
head1 : .asciiz " Tax plus tip: " 
head2 : .asciiz "\n Total cost: " 



tải về 0.57 Mb.

Chia sẻ với bạn bè của bạn:
1   2   3   4   5   6   7   8   9   10




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương