QuestionQuestion

1. Convert the following C++ program into an x86 assembly language program. Make sure to use your "Chapter 8" understanding of advanced functions, parameter passing, and local variables.

*#include <iostream>*

*using namespace std;*

*int IsSemifauxtrifactored(int value)*
*{*
* // Return 1 if a number's factors/divisors from (value - 1) to 1 sum
up to half the number value*
* // Return 0 otherwise*

* // A number is called "semifauxtrifactored" if its summed
factors/divisors equal half the number itself*
* // Integer division is used, so remainders on the halving can be lost*
* // That's why...*

* // 9 is a semifauxtrifactored number*
* // 9 cut in half with integer division is (9 / 2) = 4*
* // 9 % 8 -> 1*
* // 9 % 7 -> 2*
* // 9 % 6 -> 3*
* // 9 % 5 -> 4*
* // 9 % 4 -> 1*
* // 9 % 3 -> 0 FACTOR!*
* // 9 % 2 -> 1 *
* // 9 % 1 -> 0 FACTOR!*
* // 9 is a semifauxtrifactored number since its factors (1 + 3) equal
half the number (4)*

* // 6 is a normal number*
* // 6 cut in half with integer division is (6 / 2) = 3*
* // 6 % 5 -> 1*
* // 6 % 4 -> 2*
* // 6 % 3 -> 0 FACTOR!*
* // 6 % 2 -> 0 FACTOR! *
* // 6 % 1 -> 0 FACTOR!*
* // 6 is a normal number since its factors (1 + 2 + 3) do not equal
half the number (3)*
*}*

*int main()*
*{*
* cout << "Enter a value: ";*
* int value;*
* cin >> value;*
* value = IsSemifauxtrifactored(value);*
* if (value == 1)*
* {*
* cout << "The number is semifauxtrifactored!";*
* }*
* else*
* {*
* cout << "The number is normal";*
* }*

* cout << endl;*
* system("PAUSE");*
*}*


2. Write a basic emulator for a new computer chip

Of course a computer program is just a series of bytes sitting in a computer somewhere.
Take this series for example:
*1, 84, 1, 104, 1, 101, 2, 10, 2, 18, 1, 94, 1, 114, 1, 101, 2, 50, 1, 71,
1, 105, 1, 109, 2, 60, 1, 103, 2, 68, 1, 111, 1, 102, 1, 102, 1, 115, 2,
80, 1, 125, 1, 115, 1, 116, 1, 97, 2, 104, 1, 97, 1, 108, 1, 95, 2, 222, 2,
18, 1, 109, 1, 101, 1, 38, 2, 26, 1, 105, 1, 109, 1, 109, 1, 101, 1, 96, 2,
130, 1, 101, 1, 116, 1, 33, 3, 5, 19, 24, 1, 101, 1, 115, 1, 115, 1, 97, 1,
103, 1, 101, 2, 40, 1, 114, 1, 116, 1, 115, 1, 64, 1, 110, 1, 111, 1, 110,
1, 122, 1, 101, 1, 114, 1, 111, 1, 92, 2, 30, 1, 116, 1, 104, 1, 97, 1,
116, 2, 200, 1, 116, 1, 114, 1, 97, 1, 35, 2, 160, 1, 116, 1, 60, 1, 101,
1, 120, 2, 140, 1, 99, 1, 114, 1, 101, 1, 100, 1, 105, 1, 116, 1, 123, 2,
212, 3, 19, 17, 21, 1, 5, 1, 7, 1, 9, 1, 22, 2, 5, 1, 2, 3, 5, 11, 22, 0,
1, 1, 2, 1, 43, 1, 115, 1, 119, 1, 101, 1, 101, 2, 150, 1, 110, 1, 111, 1,
119, 1, 33, 2, 176, 1, 109, 2, 90*

Think of our EIP/offset as element 0 and start from there.

My computer chip only has three operations:

- *Opcode 1 - Write Character To Screen*
- Notice two elements in the array are used
- The first one of course is 1
- The second one is the ASCII value of the character to write to the screen
- *1 84* decodes to print 'T'
- Always increment EIP/offset by 2 when complete
- *Opcode 2 - Unconditional Jump*
- Notice two elements in the array are used
- The first one of course is 2
- The second one is the where to jump the EIP/offset to in our program
- *2 10* decodes to change the EIP/offset value directly to 10
- *Opcode 3 - Program Execution Complete*
- Immediately halt execution of the program
- This opcode only uses one element in the array
- *3* decodes to halt the program

Using x86 assembly language with MASM/Visual Studio and the Irvine library, create an emulator for this computer.
Take the program above and execute it within your emulator. A simple unencrypted phrase will print out when the program is emulated correctly.

*HINT:* Use a byte array for your data structure
*HINT:* Remember you need to maintain the EIP/offset value as the program executes
*HINT:* You may need to review section 3.4.4 in the textbook for proper array initialization

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

INCLUDE

.data
msg1 BYTE "Enter a value: ", 0
msg2 BYTE "The number is semifauxtrifactored!", 13, 10, 0
msg3 BYTE "The number is normal", 13, 10, 0

.code

main PROC

mov edx, OFFSET msg1 ; prompt user for input
call WriteString
call ReadDec ; input a number
push eax ; set argument
call IsSemifauxtrifactored ; call function

cmp eax, 1 ; check if return value is 1...

By purchasing this solution you'll be able to access the following files:
Solution1.asm and Solution2.asm.

$25.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats