DLX_code_help.pdf - Extra explanation for DLX assembly code...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Extra explanation for DLX assembly code in HW .global _exit .global _open .global _close .global _read .global _write .global _printf .align 4 .global _main _main: ;; _main as a default subroutine call itself ;; Initialize Stack Pointer (to 0xfffffc) add r14,r0,r0 lhi r14, ((memSize-4)>>16)&0xffff addui r14, r14, ((memSize-4)&0xffff) ;; Save the old frame pointer sw -4(r14),r30 ;; Save the return address sw -8(r14),r31 ;; Establish new frame pointer (pointing to bottom of stack frame) add r30,r0,r14 ;; Adjust Stack Pointer (to top of stack frame) ;; stack frame of 8 words add r14,r14,#-28 ;; Save Registers sw 0(r14),r3 sw 4(r14),r4 sw 8(r14),r5 ;; input = 5; addi r5,r0,#5 ;; location of “input” sw -12(r30),r5 ; ; retrieve “input” lw r3,-12(r30) addi r4,r0,#0 ;; test if less than 0 sge r1,r3,r4 bnez r1,L2 ;; -16(r30): location of final result; if input<0, then result=0 sw -16(r30),r0 L2: ;; ready to call; adjust stack pointer for parameter passing sub r14,r14,#4 ;; retrieve parameter from current program (caller) lw r5,-12(r30) ;; establish parameter “input” in new stack frame before calling sw 0(r14),r5
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern