PCSpim 刚刚开始的一些程序事例

1.读取两个整数,输出它们的和与差

main:
## Get first number from user, put into $t0.
li $v0, 5 # load syscall read_int into $v0
syscall # make the syscall
move $t0, $v0 # move the number read into $t0

## Get second number from user, put into $t1.
li $v0, 5 # load syscall read_int into $v0
syscall # make the syscall
move $t1, $v0 # move the number read into $t0

add $t2, $t0, $t1
sub $t3, $t0, $t1

## Print out $t2 & $t3
move $a0, $t2 # move the number to print into $a0
li $v0, 1 # load syscall print_int into $v0
syscall # make the syscall

move $a0, $t3 # move the number to print into $a0
li $v0, 1 # load syscall print_int into $v0
syscall # make the syscall

jr $ra

2. 读入一个string变量并且将其输出

.text
main:

la $a0, hello_msg # load the address of hello_msg into $a0
li $v0, 4 # load syscall print_string into $v0
syscall # make the syscall

jr $ra

.data
hello_msg: .asciiz"Hello, World!\n"

3. 读入两个整数,将其中较大的一方输出。

main:

li $v0,5
syscall
move $t0, $v0

li $v0,5
syscall
move $t1, $v0


bgt $t0, $t1, t0_bigger
move $t2,$t1
b endif

t0_bigger:
move $t2, $t0

endif:
move $a0,$t2
li $v0,1
syscall

jr $ra;

4.
5.
6.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值