从用户读取输入并在MIPS组件中将其打印回控制台

时间:2017-03-28 19:49:54

标签: assembly mips

我试图制作一个简单的程序,它将读取用户的输入并在控制台上打印回来,这是我的程序的一部分

WHERE FacID IN ( ... )

因此,我的程序等待来自用户的输入,在输入1或9之后,v0和S0(用gdb检查)的值分别为0x2而不是0x1和0x9。

编辑: 所以我才发现这个

LEAF(main)

#Print to user enter integer
    li    a0,1                # first argument fd 1
    la    a1,prompt           # second argument memory location of hello string
    li    a2,20               # lenght of string to print
    li    v0,__NR_write       # syscall write,they are defined in unistd.h
    syscall

#Raad the integer and save it in s0
    li    a0,0                # first argument for stdin is 0
    li    a1,unknown          # second argument is unknown
    li    a2,unknown          # third arg is also unknown
    li    v0,__NR_read
    syscall
    move s0, v0

所以第二个参数是__user * buf所以它指向一个* buf的指针就是这个我应该存储的地方吗? 第三个参数是size_t count但是算什么?算数的数量?

1 个答案:

答案 0 :(得分:0)

我刚才解决了这个答案

#Read the integer and save it in s0
    nop
    nop
    li    a0,0      # firs argument, for stdin is 0 ISTR, see "man 2 read"
    la    a1,(var1) # second argument load adress of var1 into a1
    li    a2,12     # third argument is count of byts 
    li    v0,__NR_read
    syscall
.data

var1:      .space     256
相关问题