19--MARIE-03--Subprograms in MARIE

19--MARIE-03--Subprograms in MARIE - Subprograms in MARIE

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

View Full Document Right Arrow Icon
Subprograms in MARIE One of the most useful features of any programming language is the ability to write subprograms – either  procedures or functions. With the limited instruction set that we have so far, writing subprograms would be  extremely difficult. We need some more instructions. There are 4 bits for the op code in MARIE which means that we can  have as many as 16 op codes. We have only used 9 so far. We need to be able to figure out (1) a way to  get to a subroutine and back again, and (2) a way to pass parameters. With the instructions that we currently have, there is NO WAY that we could implement subprograms. We  could execute a JUMP instruction to get to the subprogram, but there would be no way to return again!  The only possible way that we can get back is if we have a way of storing the program counter. We also  need a way of changing the program counter. Extending MARIE's instruction set: additional instructions JnS   (Jump and Store, op code = 0) Stores the PC at location X and jumps to location X + 1. This instruction makes it possible to write subroutines and return from them! This implies that the first  memory cell of any subprogram in MARIE will not hold an instruction at all, but a return address. Register Transfer Notation for JnS X
Background image of page 1

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

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

This document was uploaded on 02/29/2012.

Page1 / 4

19--MARIE-03--Subprograms in MARIE - Subprograms in MARIE

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online