using a trap to output characters in assembly using SPARC instruction set

 ̄綄美尐妖づ 提交于 2020-08-26 08:27:15

问题


My assignment is as follows:

Given the assembly code below, write a successfully executing trap that prints out the message “It’s a Trap” and returns to your main code.

I believe most of the work has already been done and this is likely an easy question but I'm working without any knowledge of assembly so I'm still very much in need of some help. I understand the concept of traps but not the syntax so what I'm really wondering is what kind of answer the question is looking for.

The part towards the bottom in the <> where it says "past trap code here" is it expecting me to write a "trap" subroutine like a method? Or is it supposed to be more like the portion towards the top of the code where it's written "trap: ta 0" what does the zero refer to? I believe the command 'ta' refers to "trap always" and the '0' is probably the trap number? I think the professor mentioned that there would be something like 28 traps which I really don't understand. Right above the portion that says "place trap code here" there is a reference to 'trap 15' why 15? Why do we go from trap zero to trap fifteen? What other traps are implied in this code, I don't quite understand.

Is the trap code that is expected something as simple as "ta 15" ? Also what is the syntax for returning from the trap, and where in the code should that be placed or is a trap return automatic once the trap command is executed?

.begin

Main           .equ 0xa00
ConsoleCode    .equ 0xc00
CharactorString .equ 0xf00      !Start of CharactorString in memory
BASE            .equ 0x3fffc0   !Starting point of the memory mapped 
                                !region
COUT           .equ 0x0         !0xffff0000 Console Data Port
COSTAT         .equ 0x4         !0xffff0004 Console Status Port.
TrapCode       .equ 0xff000800  !Start of trap instruction code for trap #0

               .org Main
               addcc %r0,0,%r1  !Set PSR zero bit to observe instruction ta 
                                !loading PSR values into r18
               bne EndMain      !Do not call trap if condition not meet
trap:              ta 0
EndMain:           halt             !end of routine

               .org ConsoleCode
console:       add %r0, %r0, %r2    !Clear r2
               add %r0, %r0, %r4    !Clear r4
               add %r0, %r0, %r5    !Clear r5
               add %r0, %r0, %r7    !Clear r7
               sethi BASE, %r4      !Set r4 with the base address 0xffff0000 
                                    !for Memory Map IO
            ld [StringLength], %r5  !Load the charactor string length in the 
                                    !charactor string counter register r5

Loop:       ld [%r2 + String], %r3  !Load next char into r3
            dec%r5                  !decrement the charactor string counter register r5
            andncc %r5,0,%r7        !see if it is equal to zero
            be EndConsole           !stop if the charactor string counter is zero.

Wait:       ldub [%r4+COSTAT], %r1
            andcc %r1, 0x80, %r1
            be Wait
            stb %r3, [%r4+COUT]     !Print to console
            add %r2, 4, %r2         !increment String offset (r2)
            ba Loop

EndConsole: jmpl %r15,4,%r0         !Jump back to trap code


           .org CharactorString     !The "It's a Trap!" string
           StringLength:    0xd
           String:      0x49, 0x74, 0x27, 0x73, 0x20
                        0x61, 0x20, 0x54, 0x52, 0x41 
                        0x50, 0x21


          .org TrapCode         !Start of trap instruction code for trap #15

          <paste trap code here>


.end

来源:https://stackoverflow.com/questions/49311997/using-a-trap-to-output-characters-in-assembly-using-sparc-instruction-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!