Question

In: Computer Science

. Write a sequence of instructions to calculate the following arithmetic expression and store the result...

. Write a sequence of instructions to calculate the following arithmetic expression and store the result in register CX: 20 – 6 + (-10) - (-8) + 15

Trace the contents of registers, assume initial contents are 0000 ps(there are multiple boxes)

Instruction

AX

BX

CX

DX

Remark

initial

0000

0000

0000

0000

Solutions

Expert Solution

CX:15 – 7 – 6 + (-10) + 8 - (-20)

main:

mov                 ecx, 15                                    ; eax=0 ebx=0 ecx=000F edx=0

mov                 ebx, 7                                      ; eax=0 ebx=0007 ecx=000F edx=0

sub                   ecx, eax,ebx                            ; ecx = 15-7, eax=0 ebx=0007 ecx=0008 edx=0

mov                 ebx, 6                                      ; eax=0 ebx=0006 ecx=0008 edx=0

sub                   ecx, ecx, ebx                           ; ecx = 15-7-6, eax=0 ebx=0006 ecx=0002 edx=0

mov                 ebx,10                                     ; eax=0 ebx=000A ecx=0002 edx=0

sub                   ebx,edx,ebx                             ; ebx = 0-10 = -10, eax=0 ebx=800A ecx=0002 edx=0

add                  ecx, ecx, ebx                           ; ecx = 15-7-6+(-10), eax=0 ebx=800A ecx=8008 edx=0

mov                 ebx, 8                                      ; eax=0 ebx=0008 ecx=8008 edx=0

add                  ecx, ecx, ebx                           ; ecx = 15-7-6+(-10)+8, eax=0 ebx=0008 ecx=0000 edx=0

mov                 ebx,20                                     ; eax=0 ebx=0014 ecx=0000 edx=0

sub                   ebx,edx,ebx                             ; ebx = 0-20 = -20, eax=0 ebx=8014 ecx=0000 edx=0

sub                   ecx, ecx, ebx                           ; ecx = 15-7-6+(-10)+8-(-20), eax=0 ebx=8014 ecx=0014 edx=0

ecx = 0014(hex) => 20(dec) => final result

All the values are in hexadecimal & for negative numbers first bit is used as sign bit

i hope you will understand this concept


Related Solutions

Write a program that performs the following two tasks in java Reads an arithmetic expression in...
Write a program that performs the following two tasks in java Reads an arithmetic expression in an infix form, stores it in a queue (infix queue) and converts it to a postfix form (saved in a postfix queue). Evaluates the postfix expression. Use linked lists to implement the Queue and Stack ADTs. DO NOT USE BUILT IN JAVA CLASSES
For the following exercises, write a recursive formula for each arithmetic sequence. a = {−15, −7, 1, ... }
For the following exercises, write a recursive formula for each arithmetic sequence.a = {−15, −7, 1, ... }
For the following exercises, write a recursive formula for each arithmetic sequence. a = {−1, 2, 5, ... }
For the following exercises, write a recursive formula for each arithmetic sequence.a = {−1, 2, 5, ... }
Write a C++ function that takes in an arithmetic expression in prefix notation and converts it...
Write a C++ function that takes in an arithmetic expression in prefix notation and converts it into a binary tree, such that each operation is stored in a node whose left subtree stores the left operand, and whose right subtree stores the right operand.
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented with an infix notation), then outputs this expression in prefix form and also outputs the result of the calculation. The program will first convert the input infix expression to a prefix expression (using the Stack ADT) and then calculate the result (again, using the Stack ADT). The details are provided in the following sections.
Write a program (preferably in Java) that, given an arithmetic expression, first transforms it to a...
Write a program (preferably in Java) that, given an arithmetic expression, first transforms it to a postfix form, and then computes its value (by using stack-based algorithms). Assume that all the numbers in the arithmetic expression are one-digit numbers, i.e., each of these numbers is either 0, or 1, or 2, ..., or 9. For example, your program should correctly process expressions like 2+3*4, but there is no need to process expressions like 11+22.
Consider two different implementations of the same ISA. There are four classes of instructions, Arithmetic, Store,...
Consider two different implementations of the same ISA. There are four classes of instructions, Arithmetic, Store, Load, and Branch. The clock rate and CPI of each implementation are given in the following table.              Clock Rate                  CPI-Arithmetic CPI-Store             CPI-Load    CPI-Branch P1           2.0 GHz                        1                                     2 3                                4 P2           2.5 GHz                        2    2 2                             2 Given a program with 10^6 instructions divided into classes as follows: 10% Arithmetic, 20% Store, 50% Load, and 20% Branch, which implementation is faster?
a Composite class representing arithmetic expression. Participants: Expression – interface. Operations: double calculate(), boolean isTree(). Constant...
a Composite class representing arithmetic expression. Participants: Expression – interface. Operations: double calculate(), boolean isTree(). Constant – represent a number. Leaf node. Plus, Minus, Div, Mul – binary operations. Use abstract BinaryOperation class to implement common functionality Q. Create a code implementing a pattern, Implementing Composite implies multiple class. By my estimate, at least 3. In minimal Composite implementation, classes have two methods (or a constructor and 1 method). extensive coding is not required. (using Java)
In Java, write class InfixToPostfixConverter co convert an ordinary infix arithmetic expression (assume a valid expression...
In Java, write class InfixToPostfixConverter co convert an ordinary infix arithmetic expression (assume a valid expression is entered) with single-digit integers (to make things easier) such as (6 + 2) • 5 - 8 / 4 to a postfix expression. The postfix version (no parentheses are needed) of this infix expression is 6 2 + 5 * 8 4 / - The program should read the expression into StringBuilder or String infix and use the Stack and Stack Interface class...
Using a stack, write a program that turns a simple infix arithmetic expression into a postfix...
Using a stack, write a program that turns a simple infix arithmetic expression into a postfix expression. For example, 1 + 2 * 3 becomes 2 3 * 1 +. Also, evaluate the expression to ensure the expression is correct.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT