MIPS汇编语言SYSCALL指令的用法

汇编MIPS指令集 add两数相加、syscall输出字符串、bgt分支语句、ble循环语句 第一个程序: li add 指令的使用 功能:两数相加 运行效果 第二个程序:li la syscall指令的使用 程序的分段 功能:输出Hello World 运行结果:在run I/O中输出了Hello World 第三个程序 bgt分支语句 功能: 用户输入两个数字a,b 如果a>b,则输出yes 否自输出no C语言代码 对应的汇编代码 以下可复制 #C program ... 阅读详情
AI摘要

本文详细介绍了MIPS程序中可用的系统服务,包括输入输出操作、内存分配、文件操作、终止执行等常见功能。通过步骤指导和具体示例,帮助开发者了解如何使用这些系统调用来增强程序功能。

SYSCALL functions available in MARS

Introduction

A number of system services, mainly for input and output, are available for use by your MIPS program. They are described in the table below.

MIPS register contents are not affected by a system call, except for result registers as specified in the table below.

How to use SYSCALL system services

Step 1. Load the service number in register $v0.
Step 2. Load argument values, if any, in $a0, $a1, $a2, or $f12 as specified.
Step 3. Issue the SYSCALL instruction.
Step 4. Retrieve return values, if any, from result registers as specified.

Example: display the value stored in $t0 on the console
    li  $v0, 1           # service 1 is print integer
    add $a0, $t0, $zero  # load desired value into argument register $a0, using pseudo-op
    syscall

Table of Available Services

ServiceCode in $v0ArgumentsResult
print integer1$a0 = integer to print 
print float2$f12 = float to print 
print double3$f12 = double to print 
print string4$a0 = address of null-terminated string to print 
read integer5 $v0 contains integer read
read float6 $f0 contains float read
read double7 $f0 contains double read
read string8$a0 = address of input buffer
$a1 = maximum number of characters to read
See note below table
sbrk (allocate heap memory)9$a0 = number of bytes to allocate$v0 contains address of allocated memory
exit (terminate execution)10  
print character11$a0 = character to printSee note below table
read character12 $v0 contains character read
open file13$a0 = address of null-terminated string containing filename
$a1 = flags
$a2 = mode
$v0 contains file descriptor (negative if error). See note below table
read from file14$a0 = file descriptor
$a1 = address of input buffer
$a2 = maximum number of characters to read
$v0 contains number of characters read (0 if end-of-file, negative if error). See note below table
write to file15$a0 = file descriptor
$a1 = address of output buffer
$a2 = number of characters to write
$v0 contains number of characters written (negative if error). See note below table
close file16$a0 = file descriptor 
exit2 (terminate with value)17$a0 = termination resultSee note below table
Services 1 through 17 are compatible with the SPIM simulator, other than Open File (13) as described in the Notes below the table. Services 30 and higher are exclusive to MARS.
time (system time)30 $a0 = low order 32 bits of system time
$a1 = high order 32 bits of system time. See note below table
MIDI out31$a0 = pitch (0-127)
$a1 = duration in milliseconds
$a2 = instrument (0-127)
$a3 = volume (0-127)
Generate tone and return immediately. See note below table
sleep32$a0 = the length of time to sleep in milliseconds.Causes the MARS Java thread to sleep for (at least) the specified number of milliseconds. This timing will not be precise, as the Java implementation will add some overhead.
MIDI out synchronous33$a0 = pitch (0-127)
$a1 = duration in milliseconds
$a2 = instrument (0-127)
$a3 = volume (0-127)
Generate tone and return upon tone completion. See note below table
print integer in hexadecimal34$a0 = integer to printDisplayed value is 8 hexadecimal digits, left-padding with zeroes if necessary.
print integer in binary35$a0 = integer to printDisplayed value is 32 bits, left-padding with zeroes if necessary.
print integer as unsigned36$a0 = integer to printDisplayed as unsigned decimal value.
(not used)37-39  
set seed40$a0 = i.d. of pseudorandom number generator (any int).
$a1 = seed for corresponding pseudorandom number generator.
No values are returned. Sets the seed of the corresponding underlying Java pseudorandom number generator (java.util.Random). See note below table
random int41$a0 = i.d. of pseudorandom number generator (any int).$a0 contains the next pseudorandom, uniformly distributed int value from this random number generator's sequence.See note below table
random int range42$a0 = i.d. of pseudorandom number generator (any int).
$a1 = upper bound of range of returned values.
$a0 contains pseudorandom, uniformly distributed int value in the range 0 <= [int] < [upper bound], drawn from this random number generator's sequence. See note below table
random float43$a0 = i.d. of pseudorandom number generator (any int).$f0 contains the next pseudorandom, uniformly distributed float value in the range 0.0 <= f < 1.0 from this random number generator's sequence. See note below table
random double44$a0 = i.d. of pseudorandom number generator (any int).$f0 contains the next pseudorandom, uniformly distributed double value in the range 0.0 <= f < 1.0 from this random number generator's sequence. See note below table
(not used)45-49  
ConfirmDialog50$a0 = address of null-terminated string that is the message to user$a0 contains value of user-chosen option
0: Yes
1: No
2: Cancel
InputDialogInt51$a0 = address of null-terminated string that is the message to user$a0 contains int read
$a1 contains status value
0: OK status
-1: input data cannot be correctly parsed
-2: Cancel was chosen
-3: OK was chosen but no data had been input into field
InputDialogFloat52$a0 = address of null-terminated string that is the message to user$f0 contains float read
$a1 contains status value
0: OK status
-1: input data cannot be correctly parsed
-2: Cancel was chosen
-3: OK was chosen but no data had been input into field
InputDialogDouble53$a0 = address of null-terminated string that is the message to user$f0 contains double read
$a1 contains status value
0: OK status
-1: input data cannot be correctly parsed
-2: Cancel was chosen
-3: OK was chosen but no data had been input into field
InputDialogString54$a0 = address of null-terminated string that is the message to user
$a1 = address of input buffer
$a2 = maximum number of characters to read
See Service 8 note below table
$a1 contains status value
0: OK status. Buffer contains the input string.
-2: Cancel was chosen. No change to buffer. 
-3: OK was chosen but no data had been input into field. No change to buffer.
-4: length of the input string exceeded the specified maximum. Buffer contains the maximum allowable input string plus a terminating null.
MessageDialog55$a0 = address of null-terminated string that is the message to user
$a1 = the type of message to be displayed:
0: error message, indicated by Error icon
mips汇编语言实现斐波那契数列的排列 资源包括在Mars环境下,使用mips汇编语言实现斐波那契数列的排列,并输出前n项的下标,十进制数值和十六进制数值。 立即下载

相关推荐

车载摄像头+max96712 + rk3568 调试过程中遇到的问题

本文主要讲述本人在调试rk3568通过mipi-csi2链接max967812,max96712再外接4路车载摄像头过程中遇到的问题,以及最终如何解决这些问题。图中会贴上很多重要且关键的波形图,以便读者在调试过程中进行比对,分析。 如果在调试过程中,mipi总线上的波形没得什么问题的话,还是抓图失败的情况下,需要着重检查 频率,lane数,摄像头分辨率,摄像头输入图像格式等重要配置。

Amelio Ming 2063

MIPS初见

最近的MIPS感觉都是照猫画虎,写一篇做个笔记没准还能想明白点新东西,不知道咋用一定要经常打开指令集,这里MIPS指令集。 输入输出 重要的是这个syscall指令的用法,详见MIPS汇编语言syscall指令的用法。 因此在输入输出相应的类型时,要发出对应的指令,将常用的输入输出写在这备忘: 字符串 输出 .data str: .asciiz"Hello Wolrd" .text la $a0,str li $v0,4 syscall 参照上面的样例,我们就大致清楚了怎么对字符串进

zhousiyuan0515的博客 2688

S32DS IDE调试技巧:如何用条件断点精准捕获汽车电子MCU的硬件状态变化

本文详细介绍了S32DS IDE中条件断点功能在汽车电子MCU开发中的应用技巧。通过精准捕获硬件状态变化,工程师可以高效调试外设寄存器异常、时序敏感型交互等复杂场景,大幅提升汽车电子系统的开发效率。文章还提供了多种实战案例和性能优化建议,帮助开发者充分利用S32DS的调试功能。

CAT789的专栏 207

MIPS中的syscall用法

转自:http://students.cs.tamu.edu/tanzir/csce350/reference/syscalls.html 可算搞懂syscall是咋又实现输入又实现输出的了 MIPS系统调用 (来自SPIM S20:MIPS R2000模拟器,James J. Larus,威斯康星大学麦迪逊分校) SPIM通过MIPS系统调用(系统调用)指令提供一小组类似操作系统的服务。为了请求...

Fudanqqqqq的博客 1万+

深度强化Q学习-基于微软AirSim仿真环境的自动驾驶案例(原理代码详解简易可行)

最近在学习《强化学习原理与Python实现》,肖智清著。参考第十二章的自动驾驶案例,写一篇总结,尽量做到简单可行,让有志于自动驾驶的小伙伴可以通过此篇博客可以管中窥豹,初步了解自动驾驶的强化学习训练过程。 本篇将自动驾驶问题转化为回合制的强化学习任务,设计以车辆观察图像和运行状态为输入的自动驾驶算法,并在AirSim仿真环境中进行训练和测试。本篇使用带经验回放和目标网络的基于深度Q网络算法设计并实现智能体,对经验回放、目标网络和深度Q学习算法进行简单介绍,并用代码实现。

shao918516的博客 8599

【教程4>第5章>第23节】基于FPGA的Gardner环实现——环路滤波器模块和Gardner环整体测试

1]黄凌.基于FPGA的QPSK全数字调制解调系统的设计与实现[D].南京航空航天大学[2025-02-02].DOI:10.7666/d.d166927.注意,这里包括一个NCO模块,一个内插模块,一个时偏误差检测模块,一个环路滤波器模块,在gardner环中,wk的反馈输入,变量为ww,从而构成了闭环。[4]李司.基于FPGA的数字接收机同步技术的研究与实现[D].北京交通大学[2025-02-02].DOI:10.7666/d.y1082455.:调整NCO的相位步长,控制采样时刻。

FPGA/MATLAB学习教程/源码/项目合作开发 853

mips汇编之利用syscall输出结果

彻底搞懂:mips汇编之利用syscall输出结果

你的问题在于,读书太少而想得太多。 8601

Qt项目开发实例 (含源码)

qt教程、qt项目、qt下载、qt项目实战、qt多线程。本文通过分析demo源码,QT实战的方式进行学习,学习路线是以实战为目录,全面的使用自己的学习知识,文章中编写一系列的学习游戏demo,与大家一起分享。

啊渊的专栏 14万+

syscall指令_MIPS汇编语言SYSCALL指令的用法

SYSCALL functions available in MARSIntroductionA number of system services, mainly for input and output, are available for use by your MIPS program. They are described in the table below.MIPS register...

weixin_35830270的博客 2049

【推荐系统】推荐算法:冷启动-召回-粗排-精排-重排 解读

【推荐系统】推荐算法:冷启动-召回-粗排-精排-重排 解读

Danger的博客 3760

ADRC自抗扰算法优化(PLC梯形图篇)

ADRC自抗扰算法PLC梯形图完整源代码请参看下面博客文章:ADRC自抗扰控制算法(含梯形图完整源代码和算法公式)_adrc算法_RXXW_Dor的博客-优快云博客PLC的自抗扰控制(ADRC)算法_RXXW_Dor的博客-优快云博客_adrc算法1、自抗扰控制算法,网上很多文章有所讲解,大家也可以关注韩京清教授的论文和书籍,这里就不赘述了,下面给出梯形图+SCL代码。

RXXW_Dor的博客 2282

【计算机组成原理】汇编语言[mips-c指令]

【计算机组成原理】汇编语言[mips-c指令] 计算机语言分为三类:高级语言、汇编语言和机器语言。 机器语言就是0和1的数字编码,是机器能读懂的东西,用一定长度(32或64位)的二进制数代表一条指令。

micaudience的博客 1万+

Skill的嵌套

Skill的嵌套就很简单,直接引用其他的Skill就好了。在一个 Skill 的 SKILL.md 中,可以明确指示 Claude 去读取另一个 Skill 的文档。

Criss@陈磊 953

mips中的li_MIPS学习笔记(一)

写在前面本文是根据"MIPS Assembly Language Programming CS50 Discussion and Project Book. Daniel J. Ellard"总结的。其中有大量的翻译文体以及个人的看法想法,当然,内容没有书上那么详尽。这一章节会涉及MIPS的变量的声明、数据的输入输出、取地址、分支跳转语句(用以实行循环、判断等),基本上对应于任何一门高级语言的最基...

weixin_39860583的博客 3687

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

MIPS 汇编简单学习

What ‘s the MIPS?汇编语言首先要普及一下汇编的相关知识,汇编语言是一类语言的总称,因处理器的不同,而对应着不同的机器语言指令集,产生了很多种汇编语言,如,基于INTEL 8086处理器的x8086汇编语言,还有接下来要说到的MIPS汇编语言。汇编语言不像高级语言Java,Python,Kotlin等,只要配置相关环境,同一段代码可以在不同操作系统上运行,而不同操作系统,不同的指令集,

Menzel3的博客 3615

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

MIPS我一定要灭掉你

啊

宝藏Coder的空间 761

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

MIPS汇编利用syscall在Run I/O输出

MIPS汇编利用syscall在Run I/O输出实现语句分析对于服务号的分析 实现 ==我的语句运行想在Run I/O中输出$s3中的值,即查看结果是否为30,==则需要加入如下语句: 此时便可以查看 语句分析 第1步: 在寄存器v 0 中 加 载 服 务 号 。 第2步:将想输出的参数值(如果有的话)载入a0、a 1 、 a1、a1、a2或$f12中。 第3步:发出SYSCALL指令。 第4步:如果有的话,按规定从结果寄存器中获取返回值。 对于服务号的分析 这里$s3中的值是整形,所以我们调用l

changyana的博客 843

[嵌入式系统-37]:龙芯1B 开发学习套件 -7-MIPS指令集

MIPS汇编中的函数定义通常遵循一定的约定和结构。# 函数声明# 函数体# 返回JR $ra # 返回,使用$ra中保存的返回地址函数声明:在MIPS汇编中,函数声明由标签表示,例如。函数的开始由该标签标识。函数体:在函数的标签之后,是函数的实际代码内容,包括各种指令、操作和逻辑。返回指令:在函数体的结尾通常会有一个返回指令,用于将控制流返回到调用函数的地方。在MIPS中,使用JR $ra指令来实现返回操作,这里的$ra寄存器保存了函数调用前的返回地址。

文火冰糖(王文兵)的博客 2627

《汇编语言程序设计》学习笔记(5)五、MIPS汇编

5.1 MIPS32架构与指令集初步 5.1.1 MIPS32架构与指令集初步-1 MIPS架构——最经典的RISC 5.1.2 MIPS32架构与指令集初步-2 MIPS的经典流水线结构 5.1.3 MIPS32架构与指令集初步-3 指令集的特点(与x86指令集对比) MIPS32里面呢有一个寄存器 就是0号寄存器比较特殊 就是它的值啊永远是0 它就认为...

Henry1991back的博客 1932

MIPS汇编语言学习笔记13:Dividing Integers part 1

程序功能:计算两个整数相除的结果,并打印输出。 代码提示:参考MIPS汇编语言学习笔记03:print HelloWorld中的MIPS pdf文档,里面有MIPS指令。经查询发现使用div指令即可。随即写出代码。 代码: .data intA: .word 8 intB: .word 4 .text lw $t1, intA lw $t2, intB div $a0, $t1, $t2 # print li $v0, 1 syscall 本文已收录到:MIPS汇编语

m0_61491107的博客 290

【MIPS】MIPS指令集:内嵌汇编asm语法介绍

内嵌汇编指令"move %0,%1\n\t"中的move还不是真正的MIPS汇编指令,MIPS中的move指令的2个操作数是寄存器,而此处move的操作数是c语言中的变量。“memory”就是通知GCC编译器,此段内嵌汇编修改了memory中的内容,asm之前的c代码块和之后的c代码块看到的memory可能是不一样的,对memory的访问不能依赖之前的缓存,需要重新加载。操作符就使用MIPS汇编指令中的助记符,操作数可以是%0,%1,%2形式的占位符,来表示c语言中变量ret、a和b。整个程序功能很简单。

qq_45869788的博客 904

MIPS汇编语言HelloWord

编程第一步,输出HellWorld。

学不可以已的博客 401

计算机组成mooc作业:MIPS汇编程序设计

前言 (计算机组成北大mooc第二节课的课后作业,拖了一个星期终于着手做了qaq。)题目是两道使用MIPS指令体系完成简单程序设计的实战,编程内容很简单,但是自学完整的mips指令体系工作量还是不小的。 1.MARS准备 题目推荐使用MARS(MIPS Assembler and Runtime Simulator)集成开发环境作为实验平台。官网链接:https://courses.missour...

FELD的博客 3381

汇编语言与计算机系统结构笔记18】MIPS指令集与汇编程序设计 & 异常处理

本次笔记内容: 28.MIPS指令集与汇编程序设计-2 补充:MIPS32异常处理 注:我找到了对应内容的课件,请见我于GitHub的CS笔记仓库。 本节课对应幻灯片:汇编语言程式设计-MIPS.pdf,第49页起。 在B站视频中,缺了一节课,即 ‘MIPS32异常处理’ ,感谢 UP 主东南偏南2018做的补充:汇编语言程序设计(清华大学张悠慧)P27。 我们讲 MIPS32 ,主要集中在其特色部分。 文章目录 P49 定长指令造成了一些困扰 P51 指令编码 P5..

Android062003的博客 580
上一篇: MIPS 通用寄存器
下一篇: 尴尬君正,是如何被“创新”带到沟里去的?
csshuke
博客等级 码龄16年 1517粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值