assembly - 回显码:从打印变为返回
问题描述
我想在程序集中编写一个与 echo 具有类似行为的函数,但我不想打印给定的字符,而是想将其更改为将被调用的函数,而不是打印它返回给定的输入。下面的代码是我要修改的回声行为
!
! main - Repeat the following in an infinite loop: Wait (in a busy loop)
! until an input character is available. Read it in. Then wait
! (in a busy loop) until the output is ready and write the character
! to the output.
!
! r2 = character
! r3 = ptr to SERIAL_STAT word in the memory-mapped area.
! r4 = ptr to SERIAL_DATA word in the memory-mapped area.
! r5 = serial status word
!
main:
set STACK_START,r15 ! Initialize the stack reg
set SERIAL_STAT,r3 ! Initialize ptr to SERIAL_STAT word
set SERIAL_DATA,r4 ! Initialize ptr to SERIAL_DATA word
loop: ! LOOP:
wait1: ! WAIT1:
load [r3],r5 ! r5 := serial status word
btst 0x00000001,r5 ! if status[charAvail] == 0 then
be wait1 ! . goto WAIT1
load [r4],r2 ! Get the character
cmp r2,'\n' ! if char != \n
be charOK ! .
cmp r2,'\r' ! . and char != \r
be charOK ! .
cmp r2,' ' ! . and char < ' ' char then
bge charOK ! .
mov '?',r2 ! char := '?'
charOK: ! endIf
cmp r2,0x7e ! if char > 7e char then
ble charOK2 ! .
mov '?',r2 ! char := '?'
charOK2: ! endIf
wait2: ! WAIT2:
load [r3],r5 ! r5 := serial status word
btst 0x00000002,r5 ! if status[outputReady] == 0 then
be wait2 ! . goto WAIT2
store r2,[r4] ! send char in r2 to serial output
cmp r2,'q' ! if char == 'q' then
bne cont ! .
debug ! debug
cont: ! endIf
jmp loop ! ENDLOOP
STACK_START = 0x00ffff00
SERIAL_STAT = 0x00ffff00
SERIAL_DATA = 0x00ffff04
我遇到的麻烦是我不太擅长阅读汇编语言,所以我并不完全知道如何在不破坏代码的情况下擦除循环,或者在哪里插入返回指令。
解决方案
推荐阅读
- docker - 如何在 CI &CD VSTS 中使用 kubernetes 和 nginx 中的环境变量替换 angular config.json 的字段值
- javascript - 如何设置变量以满足 for 循环循环之外的条件?
- python - 如何在 python-weka-wrapper 中为关联规则准备数据?
- android - 如何在不编写 php 代码的情况下将用户从 android 应用程序登录到 wordpress 网站
- python - 在 RDD 上使用 python 类方法
- python - 如何减去具有不同填充值的数据帧
- javascript - 选项 net::ERR_EMPTY_RESPONSE Angular - CORS 设置是什么?
- ios - 在播放视频ios swift中显示广告
- html - 在无序列表中将带有图像的文本垂直居中
- rebus - 如何为 Rebus 编写中间件?