Common c control flow instructions, C/C++ Programming

Assignment Help:

In this Lab you will code 8086 assembler equivalents (Virgo) for common C control flow instructions. This will give you an appreciation for how control flow is implemented in assembly (and machine) language. You will find that it is not quite as simple as it is with a high-level language. See special instructions for submission at the end of this file.This lab contains a BONUS section worth an additional 4 points on your final mark! Here is a list of the C instructions for which you will code assembly language equivalents:

If statement
C code
if (condition) {
statements
}
If-Else statement
C code
if (condition) {
then_statements
} else {
else_statements
}
While loop
C code
while (condition) {
statements
}
Do-While loop
C code
do {
statements
} while (condition);
For loop
C code
for (initialization; condition; increment) {
statements
}
Switch statement
C code
switch (expression) {
case val_1:
case_1_statements
case val_2:
case_2_statements

case val_n:
case_n_statements
default:
default_statements
}
Normally, C Switch statements have a Break statement at the end of each case. You will also need to implement Break and Continue statements which can be used inside some of these control flow instructions.
Break statements
A Break statement can occur inside a C loop or Switch statement. It is implemented as an unconditional branch to a label immediately following the loop or Switch statement.
Continue statements
A Continue statement can occur inside a C loop. For While and Do-While loops, it is implemented as an unconditional branch to a label for the condition test of the While or Do-While statement.
A Continue statement in a For loop is implemented as an unconditional branch to a label immediately preceding the code to implement the increment statement.

Note that the assembly code you develop for these C-structure equivalents need only be shown as pseudocode; that is, since the actual conditions are not given, neither the test for the condition nor the jump statement for this test can actually be shown. Typically, the test will be some sort of compare (cmp) instruction and the jump will be one of the many jmp variants. It is only necessary to state that a test must be done at a certain point and that a jump relating to that test should then be done at some other point. In the second and third parts of the assignment, you will code and test two of these instructions using actual assembly language.

Coding for the IF statement is given below as an example of the syntax required. Use a similar syntax for the remaining control flow instructions.

If statement
C code
if (condition) {
statements
}
Assembler pseudo-code
IF:
test condition
jump to Next if false
assembly code for statements
Next:
Part A) Write pseudo-code for the remaining five control flow statements given above and for the Break and Continue statements.
Part B) Code a Do-While loop for the following C-code example in Virgo assembly language (assume
int's are words of 2 bytes). Place each C-code statement at the appropriate place in your assembly code as a comment:
int x = 0;
do
{
x++;
if (x == 5) continue;
sum += x;
} while (x < 10);
Bonus) Code a Switch statement for the following C-code example in assembly language (assume int's are words of 2 bytes). Place each C-code statement at the appropriate place in your assembly code as a comment:

int a;
int b = 0x12;
int c = 0x34;
int p = some constant value;
switch (p)
{
case 0: a = b + c; break;
case 1: a = b - c; break;
case 3: a = b; break;
case 7: a = c; break;
default: a = 0;
}


Related Discussions:- Common c control flow instructions

[email protected], Write a program to find the area under the curve y =...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Calculate the average assignment grade, 1. The main program must be in a fi...

1. The main program must be in a file called A4.cpp 2. The data must be read in from a data file.  The user must enter the filename.  A sample data file will be provided on Mood

Decoding, how to decode a number from mobile keypad

how to decode a number from mobile keypad

Sdsds, Given an integer n and a permutation of numbers 1, 2 ... , n-1, n wr...

Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation. If the given

C CODING, HOW THE C PROGRAM CODING IMPLEMENTED DY ITSELF UNDERSTANDING . AL...

HOW THE C PROGRAM CODING IMPLEMENTED DY ITSELF UNDERSTANDING . ALSO HOW I CAN A BECOME A GOOD PROGRAMMER IN C WHAT I DO FOR GOOD PROGRAMMING ,TELL ME HOW C CODING DEVELOP DY ITSELF

Define the system oriented data files, Define the System Oriented Data File...

Define the System Oriented Data Files? System-oriented data files are further closely related to the computer's operating system than Stream- oriented data files and they are s

Inheritance and polymorphism, The zipped folder int_collection.zip (downloa...

The zipped folder int_collection.zip (downloaded from Blackboard) contains an abstract class AbstractIntCollection and two interfaces: IntList and IntStack. The abstract class cont

Msp, A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of t

Memory management by c program, Memory management by c program: Write ...

Memory management by c program: Write a program to memory management in c program unsigned max( unsigned, unsigned );   int BaseMemBlocks::allocBlock( size_t sz )

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd