如何刷新 mars mips 中的提示? [英] How refresh the prompt in mars mips?

查看:78
本文介绍了如何刷新 mars mips 中的提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我尝试清除 MARS(mips 汇编程序)的默认提示 i/o,并且真诚地,不知道如何做到这一点.在程序运行期间,我可以使用哪些代码或系统调用来刷新屏幕?

抱歉信息不全.我说的是 MARS 中存在的模拟 MIPS 控制台输出/输入".我的问题是是否可以在程序运行期间清除此控制台以及任何代码实现.

解决方案

有两种基本方法可以做到这一点,但它们都涉及捕获 clear 命令的输出[或使用其他 TTY 控件序列ala libcurses].在下面的示例中,我捕获了 clear 命令的输出并对其进行了十六进制转储以获取 clear: .byte ...

下面只是清屏并输出经过的秒数,一个简单的清屏演示.其他 xterm ESC 序列也是可能的,就像在任何 C 程序中一样.

<小时>

如果我们在命令行模式下调用 mars:mars myfile.s,那么 syscall 4 将连接到 xterm 窗口和以下内容将工作:

 .datamsg: .asciiz "你好世界\n"清除:.byte 0x1B,0x5B,0x33,0x3B,0x4A,0x1B,0x5B,0x48,0x1B,0x5B,0x32,0x4A清除:.byte 0x00.文本.globl 主主要的:主循环:#清屏la $a0,清除里 $v0,4系统调用# 输出一个数字移动 $a0,$t7里 $v0,1系统调用addiu $t7,$t7,1# 稍等一会立$t6,500000主延迟:subiu $t6,$t6,1bnez $t6,main_delayj 主循环

<小时>

然而,如果我们在 GUI 模式下调用 mars(例如 mars),系统调用 4 将转到它的正常窗口窗格 [这不会> 理解类似 xterm 的转义序列],因此,上述方法行不通.

但是,如果我们从程序中打开 /dev/tty,对其进行写入系统调用,我们可以将转义序列发送到包含 xterm 窗口mars 命令被调用.

这更复杂,因为我们必须手工完成所有事情,但它有效:

 .data文件:.asciiz "/dev/tty"msg: .asciiz "你好世界\n"清除:.byte 0x1B,0x5B,0x33,0x3B,0x4A,0x1B,0x5B,0x48,0x1B,0x5B,0x32,0x4A.byte 0x00sprintf_buf:.space 80sprintf_bufe:.文本.globl 主主要的:li $v0,13 # 打开文件la $a0,ofile # 要打开的文件名li $a1,1 # 1=O_WRONLYli $a2,0 # 模式 [忽略]系统调用move $s7,$v0 # 记住打开的单位主循环:#清屏la $a1,clearjal fputs# 格式化进度号移动 $a0,$t7addiu $t7,$t7,1jal sprintf# 输出进度号jal fputs#延迟一点里 $t0,500000主延迟:subiu $t0,$t0,1bnez $t0,main_delayj 主循环# sprintf -- 格式化数字## 返回:# a1 -- 指向缓冲区的指针## 参数:# a0 -- 要输出的数字冲刺:la $a1,sprintf_bufe # 获取缓冲区指针苏比 $a1,$a1,1sb $zero,0($a1) # 存储 EOSli $t1,10 # 得到十进制基数sprintf_loop:div $a0,$t1 # 得到 (num/10) 和 (num % 10)mfhi $t0 # 隔离数字 (num % 10)# 存储 ascii 数字添加 $t0,$t0,'0'苏比乌 $a1,$a1,1sb $t0,0($a1) # 存储数字mflo $a0 # num/= 10bnez $a0,sprintf_loopjr $ra# fputs -- 输出字符串到控制台"## 参数:# s7 -- 文件描述符# a1 -- 指向字符串的指针输出:move $a2,$a1 # 获取缓冲区地址# 获取字符串长度fputs_loop:lb $t0,0($a2) # 获取下一个字符——是 EOS 吗?addiu $a2,$a2,1 # 增加长度/缓冲区指针bnez $t0,fputs_loop # 不,循环subu $a2,$a2,$a1 # 获取长度move $a0,$s7 # 获取文件描述符li $v0,15 # 写入的系统调用系统调用jr $ra # 返回

Good , I try clear the default prompt i / o of MARS ( mips assembler ) and sincerely , not sure how make this. Which code or syscall can I use for refresh the screen During the program running ?

EDIT: Sorry for poor informations. I say about the "Simulate MIPS console Output/input" that exists in MARS. My question is if it's possible clear this console during the program running, with any code implementation.

解决方案

There are two basic ways to do this, but they both involve capturing the output of the clear command [or using other TTY control sequences ala libcurses]. In the examples below, I captured the output of the clear command and did a hex dump of it to get the data for the clear: .byte ...

The following just clear the screen and output the number of elapsed seconds, a simple demo of screen clear. Other xterm ESC sequences are possible, just like in any C program.


If we invoke mars in command line mode: mars myfile.s, then syscall 4 will connected to the xterm window and the following will work:

    .data
msg:    .asciiz     "hello world\n"
clear:  .byte   0x1B,0x5B,0x33,0x3B,0x4A,0x1B,0x5B,0x48,0x1B,0x5B,0x32,0x4A
eclear:
        .byte 0x00

    .text
    .globl main
main:

main_loop:
    # clear the screen
    la      $a0,clear
    li      $v0,4
    syscall

    # output a number
    move    $a0,$t7
    li      $v0,1
    syscall
    addiu   $t7,$t7,1

    # wait a bit
    li      $t6,500000
main_delay:
    subiu   $t6,$t6,1
    bnez    $t6,main_delay
    j       main_loop


However, if we invoke mars in GUI mode (e.g. mars), syscall 4 will go to its normal window pane [which does not understand xterm-like escape sequences] and, so, the above will not work.

But, if we open /dev/tty from within the program, do a write syscall to it, we can send escape sequences to the containing xterm window that the mars command was invoked from.

This is more elaborate because we have to do everything by hand, but it works:

    .data
ofile:  .asciiz     "/dev/tty"
msg:    .asciiz     "hello world\n"
clear:  .byte   0x1B,0x5B,0x33,0x3B,0x4A,0x1B,0x5B,0x48,0x1B,0x5B,0x32,0x4A
        .byte 0x00

sprintf_buf:
    .space  80
sprintf_bufe:

    .text
    .globl main
main:
    li      $v0,13                  # open file
    la      $a0,ofile               # filename to open
    li      $a1,1                   # 1=O_WRONLY
    li      $a2,0                   # mode [ignored]
    syscall
    move    $s7,$v0                 # remember open unit

main_loop:
    # clear the screen
    la      $a1,clear
    jal     fputs

    # format the progress number
    move    $a0,$t7
    addiu   $t7,$t7,1
    jal     sprintf

    # output the progress number
    jal     fputs

    # delay a bit
    li      $t0,500000
main_delay:
    subiu   $t0,$t0,1
    bnez    $t0,main_delay
    j       main_loop

# sprintf -- format a number
#
# RETURNS:
#   a1 -- pointer to buffer
#
# arguments:
#   a0 -- number to output
sprintf:
    la      $a1,sprintf_bufe        # get buffer pointer
    subi    $a1,$a1,1
    sb      $zero,0($a1)            # store EOS

    li      $t1,10                  # get decimal base

sprintf_loop:
    div     $a0,$t1                 # get both (num / 10) and (num % 10)
    mfhi    $t0                     # isolate digit (num % 10)

    # store ascii digit
    addi    $t0,$t0,'0'
    subiu   $a1,$a1,1
    sb      $t0,0($a1)              # store the digit

    mflo    $a0                     # num /= 10
    bnez    $a0,sprintf_loop

    jr      $ra

# fputs -- output string to "console"
#
# arguments:
#   s7 -- file descriptor
#   a1 -- pointer to string
fputs:
    move    $a2,$a1                 # get buffer address

# get string length
fputs_loop:
    lb      $t0,0($a2)              # get next char -- is it EOS?
    addiu   $a2,$a2,1               # increment length/buffer pointer
    bnez    $t0,fputs_loop          # no, loop

    subu    $a2,$a2,$a1             # get the length

    move    $a0,$s7                 # get file descriptor
    li      $v0,15                  # syscall for write
    syscall

    jr      $ra                     # return

这篇关于如何刷新 mars mips 中的提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆