Ask Assembly Expert

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 loopC 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 pseudo-code; 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;
}

Assembly, Programming

  • Category:- Assembly
  • Reference No.:- M91869455
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Assembly

Really need to find a correct answer to this questionwrite

Really need to find a correct answer to this question: Write a MIPS assembly program that can search for a number that is entered by a user in an array with 20 integer number. Make sure it also prints the index of the ar ...

Question a sequence string of one-byte ascii characters is

Question : A sequence (string) of one-byte ASCII characters is stored at memory location $600 onward. A second sequence of equal length is stored at memory location $700 onward. Each sequence ends with the character $0 ( ...

Task 1using masm sdk write an assembly language program

TASK 1 Using MASM SDK, write an assembly language program which converts an integer inputted via the console to binary. Your program should be well commented and well formatted. TASK 2 Using MASM SDK, write an assembly l ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As