1. Homepage
  2. Programming
  3. Computer Programming Project Task 3: Controlling the Flow: the GOTO solution!

Computer Programming Project Task 3: Controlling the Flow: the GOTO solution!

Engage in a Conversation
NetherlandsVUVrije Universiteit AmsterdamComputer ProgrammingC dreaded BinariesGOTO

3 - Controlling the Flow: the GOTO solution!

What to implement

Update your step function. CourseNana.COM

Instructions

  • OP_GOTO
  • OP_IFEQ
  • OP_IFLT
  • OP_IF_ICMPEQ

In order to pass test3, correctly implement all of the functions and instructions listed above. CourseNana.COM

Introduction

In this chapter, you will be tasked with implementing basic branching. The IJVM instruction set contains four instructions that control the flow of the program: GOTOIFEQIFLT and IF_ICMPEQ. The idea behind the GOTO instruction is simple: add an offset to the program counter, and continue executing the program from that address. Other instructions such as IFEQ do the same, but only branch if a certain condition is met. CourseNana.COM

To illustrate how GOTO should behave, consider the following example program which prints 13 (and skips printing 2): CourseNana.COM

.main
L1:
  BIPUSH 0x31 // Push  ’1’
  OUT         // Print ’1’
  GOTO L3     // Jump to L3

L2:
  BIPUSH 0x32 // Push  '2'
  OUT         // Print ’2’

L3:
  BIPUSH 0x33 // Push  '3'
  OUT         // Print ’3’
  HALT

.end-main

In contrast to the instructions you've implemented so far, the GOTOIFEQIFLT and IF_ICMPEQ instructions take a signed short as an argument. The figure below illustrates the layout of different IJVM instruction formats: CourseNana.COM

Figure 3.1: Layout of different IJVM instruction formats. CourseNana.COM

The suggested approach

Start with implementing the GOTO instruction, then move to the other three. CourseNana.COM

OpCodeInstructionArgsDescription
0xA7GOTOshortIncrement the program counter by a (signed) short
0x99IFEQshortPop a word from the stack and branch if it equals zero
0x9BIFLTshortPop a word from the stack and branch if it is less than zero
0x9FIF_ICMPEQshortPop two words from the stack and branch if they are equal

Hints

  • Keep in mind that the offset is calculated based on the program counter value at the beginning of the branching instruction, so you might obtain an incorrect value if you directly increment your program counter to obtain the argument. CourseNana.COM

  • Some instructions, such as the branching instructions, have arguments that are signed, while other instructions have an unsigned argument. In general, instructions that take an index as argument have an unsigned argument, while other instructions have signed arguments. CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Netherlands代写,VU代写,Vrije Universiteit Amsterdam代写,Computer Programming代写,C代写, dreaded Binaries代写,GOTO代写,Netherlands代编,VU代编,Vrije Universiteit Amsterdam代编,Computer Programming代编,C代编, dreaded Binaries代编,GOTO代编,Netherlands代考,VU代考,Vrije Universiteit Amsterdam代考,Computer Programming代考,C代考, dreaded Binaries代考,GOTO代考,Netherlandshelp,VUhelp,Vrije Universiteit Amsterdamhelp,Computer Programminghelp,Chelp, dreaded Binarieshelp,GOTOhelp,Netherlands作业代写,VU作业代写,Vrije Universiteit Amsterdam作业代写,Computer Programming作业代写,C作业代写, dreaded Binaries作业代写,GOTO作业代写,Netherlands编程代写,VU编程代写,Vrije Universiteit Amsterdam编程代写,Computer Programming编程代写,C编程代写, dreaded Binaries编程代写,GOTO编程代写,Netherlandsprogramming help,VUprogramming help,Vrije Universiteit Amsterdamprogramming help,Computer Programmingprogramming help,Cprogramming help, dreaded Binariesprogramming help,GOTOprogramming help,Netherlandsassignment help,VUassignment help,Vrije Universiteit Amsterdamassignment help,Computer Programmingassignment help,Cassignment help, dreaded Binariesassignment help,GOTOassignment help,Netherlandssolution,VUsolution,Vrije Universiteit Amsterdamsolution,Computer Programmingsolution,Csolution, dreaded Binariessolution,GOTOsolution,