首页 > 解决方案 > 回显码:从打印变为返回

问题描述

我想在程序集中编写一个与 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

我遇到的麻烦是我不太擅长阅读汇编语言,所以我并不完全知道如何在不破坏代码的情况下擦除循环,或者在哪里插入返回指令。

标签: assembly

解决方案


推荐阅读