repeat until command n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Repeat Until Command PowerPoint Presentation
Download Presentation
Repeat Until Command

Loading in 2 Seconds...

play fullscreen
1 / 9

Repeat Until Command - PowerPoint PPT Presentation


  • 140 Views
  • Uploaded on

Repeat Until Command. Code Functions. run P. Run the program P and then halt, starting and finishing with an empty stack Execute the command C, possibly updating variables, but neither expanding nor contracting the stack

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Repeat Until Command' - akando


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
code functions
Code Functions

run P

Run the program P and then halt, starting and finishing with an empty stack

Execute the command C, possibly updating variables, but neither expanding nor contracting the stack

Execute the expression E, pushing its result on to the stack top, but having no other effect

Push the value of the constant or variable named V on to the stack top

Pop a value from t he stack top, and store it in the variable named V

Elaborate the declaration D, expanding the stack to make space for any constants and variables declared therein

execute C

evaluate E

fetch V

assign V

elaborate D

abstract machine tam instructions
Abstract Machine TAM Instructions

Fetch an n-word object from the data address (d+register r), and push it on the stack

Push the data address (d+register r) on to the stack

Pop a data address from the stack, fetch an n-word object from that address, and push it on to the stack

Push the 1-word literal value d on to the stack

Pop an n-word object from the stack, and store it at the data address (d+register r)

Pop an address from the stack, then pop an n-word object from t he stack and store it at that address

Call the routine at code address (d+register r), using the address in register n as the static link

Pop a closure (static link and code address) from the stack, then call the routine at that code address

Return from the current routine: pop an n-word result from the stack, then pop the topmost frame, then pop d words of arguments, then push the result back on to the stack

Push d words (uninitialized) on to the stack

Pop an n-word result from the stack, then pop d more words, then push the result back on to the stack

Jump to code address (d+register r)

Pop a code address from the stack, then jump to that address

Pop a 1-word value from the stack, then jump to code address (d+register r) if and only if that value equals n

Stop execution of the program

LOAD(n) d[r]

LOADA d[r]

LOADI(n)

LOADL d

STORE(n) d[r]

STOREI(n)

CALL(n) d[r]

CALLI

RETURN(n) d

PUSH d

POP(n) d

JUMP d[r]

JUMPI

JUMPIF(n) d[r]

HALT

while command
While Command
  • execute [[while E do C]] =

JUMP h

    • g: execute C
    • h: evaluate E

JUMPIF(1) g

while command1

30: JUMP 35 // JUMP h

g: 31: LOAD i

32: LOADL 2

33: CALL sub

34: STORE i

h: 35: LOAD i

36: LOADL 0

37: CALL gt

38: JUMPIF(1) 31 // JUMPIF(1) g

While Command
  • execute [[while i > 0 do i := i – 2]]
    • execute [[i := I – 2]]
    • execute [[i > 0]]
while command2
While Command

public Object visitWhileCommand(WhileCommand ast, Object o) {

Frame frame = (Frame) o;

int jumpAddr, loopAddr;

jumpAddr = nextInstrAddr;

// saves the next instruction address (g:) to put in JUMP command

emit(Machine.JUMPop, 0, Machine.CBr, 0);

// puts the JUMP h instruction in obj file

loopAddr = nextInstrAddr;

// this is address g:

ast.C.visit(this, frame);

// this generates code for C

patch(jumpAddr, nextInstrAddr);

// this establishes address h: that was needed in the JUMP h statement

ast.E.visit(this, frame);

// this generated code for E

emit(Machine.JUMPIFop, Machine.trueRep, Machine.CBr, loopAddr);

// this generated code to check expression, if false to address g:

return null;

}

repeat command
Repeat Command
  • execute [[repeat C until E]] =

g: execute C

evaluate E

JUMPIF(1) g

repeat command1

g: 31: LOAD i

32: LOADL 2

33: CALL sub

34: STORE i

35: LOAD i

36: LOADL 0

37: CALL lt

38: JUMPIF(0) 31 // JUMPIF(0) g

Repeat Command
  • execute [[repeat i := i – 2 until i < 0 do ]]
    • execute [[i := i – 2]]
    • execute [[i > 0]]
repeat command2
Repeat Command

public Object visitRepeatCommand(RepeatCommand ast, Object o) {

Frame frame = (Frame) o;

int jumpAddr, loopAddr;

// emit(Machine.JUMPop, 0, Machine.CBr, 0);

// jumpAddr = nextInstrAddr;

loopAddr = nextInstrAddr;

ast.C.visit(this, frame);

// patch(jumpAddr, nextInstrAddr);

ast.E.visit(this, frame);

emit(Machine.JUMPIFop, Machine.falseRep, Machine.CBr, loopAddr);

return null;

}