Answered Essay: Computer Science: Assembly Language for x86 Processors

Computer Science: Assembly Language for x86 Processors

VS 2017 [C++]

Integer_Expression_Calculation

Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the expression Res = (A + B) – (C + D), using registers and variables.

Several steps are suggested:

1. In the data segment, define variables ordered by: varA, varB, varC, varD, and Res with some integers initialized

2. In the code segment

– calculate (A + B) – (C + D)

– save the result in Res

You can copy the following to fill the blanks with your implementations. Please do not use more than six instructions.

TITLE Chapter 3, Problem 1 (Integer Expression.asm) : Program: ; Description: calculates Res : Student: : Date: : Class: Chapter 3, Problem 1 (A+ B) - (C +D), using registers and variables uames Hope 02/09/2015 CSCI 241 Instructor: Mr. Ding .386 model flat,stdcall stack 4096 ExitProcess proto, dwExitcode: dword .data : define variables varA, varB, varC, varD, and Res . code inl proc ; calculate Res (A + B) - (C + D) : calculate (A B)(C D) ; save the result in Res invoke ExitProcess,O mainl endp end mainl

When finished, test your program in debugger. If you define DWORD varA as 10, varB 20, varC 30, and varD 40, Res should be -40. From your VS memory windows, when you enter &varA, the result would be like this:

where 0a 00 00 00 means 10, 14 00 00 00 is 20, 1e 00 00 00 is 30, 28 00 00 00 is 40, and d8 ff ff ff is -40

TITLE Chapter 3, Problem 1 (Integer Expression.asm) : Program: ; Description: calculates Res : Student: : Date: : Class: Chapter 3, Problem 1 (A+ B) – (C +D), using registers and variables uames Hope 02/09/2015 CSCI 241 Instructor: Mr. Ding .386 model flat,stdcall stack 4096 ExitProcess proto, dwExitcode: dword .data : define variables varA, varB, varC, varD, and Res . code inl proc ; calculate Res (A + B) – (C + D) : calculate (A B)(C D) ; save the result in Res invoke ExitProcess,O mainl endp end mainl

Expert Answer

 

DATA SEGMENT is the starting point of the Data Segment in a Program and DATA is the name given to this segment and SEGMENT is the keyword for defining Segments, Where we can declare our variables. for the above programm you need to declare 5 variable varA, varB, varC, varD and res to store result of a program.

DATA SEGMENT

varA DW 10

varB DW 20

varC DW 30

varD DW 40

Res DW ?

ENDS

in above data segment we initialized varA to 10, varB to 20, varCto 30 and varC to 40.

for the variable Res we defined it as Res DW ?, question mark stands for value of register is not initialized.

Selection of data type is DW data type, DW stants for Define Word (Size 2 Byte).

In Assembly programming, the variable are all defined by bytes only.

DB – Define Byte (Size – 1 Byte)

DW – Define Word (Size – 2 Byte)

DD – Define Double word (Size – 4 Bytes)

DQ – Define Quad word (Size – 8 Bytes)

DT – Define Ten Bytes (Size – 10 Bytes)

Now lets move towords the CODE SEGMENT

we need to solve (A+B)-(C+D) equation in only 6 steps and store the result in Res variable

CODE SEGMENT  
    ASSUME DS:DATA CS:CODE
START:
      MOV AX,DATA
      MOV DS,AX
 
      MOV AX,varC
      ADD varD, AX
      
      MOV AX, varA
      ADD AX, varB

      SUB AX, varD

      MOV Res,AX  
 
      MOV AH,4CH
      INT 21H      
ENDS

After Assuming DATA and CODE Segment, Still it is mandetory to initialize Data Segment to DS register. keyword MOV is used to move second element into the first element. But we cannot move DATA Directly to DS due to MOV commands restriction, Hence we move DATA to AX and after that from AX to DS. AX is the first and most important register in the ALU unit.

ADD & SUB keywords is used for addition and substraction of numbers respectively here are the some rules/ permutations do that

First permutation :- REG , memory means Register can be added with memory.

Second permutation :- memory , REG means memory can be added with Register.

Third permutation :- REG, REG means Register can be added with Register.

Fourth permutation :- memory , immediate means memory can be added with immediate.

Fifth permutation :- REGimmediate means Register can be added with immediate.

the last two line in code segment is used to exit to dos or exit to operating system. Standard Input and Standard Output related Interupts are available in INT 21H which is also called as DOS interrupt.

So our final code will be like this, after each line we will add comments for understanding purpose

DATA SEGMENT

varA DW 10 ; declare and intialize variable varA with value 10

varB DW 20   ; declare and intialize variable varB with value 20

varC DW 30    ; declare and intialize variable varC with value 30

varD DW 40    ; declare and intialize variable varD with value 40

Res DW ?    ; declare variable Res with no initialization

ENDS

CODE SEGMENT  
    ASSUME DS:DATA CS:CODE
START:
      MOV AX,DATA
      MOV DS,AX
 
      MOV AX,varC   ; move value of variable varC in to AX
      ADD varD, AX  ; add varD and varC(AX) and result is stored in varD(C+D)
      
      MOV AX, varA  ; move value of variable vaAC in to AX
      ADD AX, varB  ; add varA(AX) and varB and result is stored in AX(A+B)
      SUB AX, varD ; Substract varD from AX and result is stored in AX

      MOV Res,AX  ; move AX to variable Res
 
      MOV AH,4CH
      INT 21H      
ENDS
Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.