Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Assignment 4 (30 points) Due at Midnight, Monday, March 12 In this program you are to write a main function and an Adder function

Programming Assignment 4 (30 points) Due at Midnight, Monday, March 12 In this program you are to write a main function and an Adder function as described below and as specified in the prog4SP18Student.asm file from the class website. The Adder function will simulate a full adder circuit to add up 3 bits using the AND, OR and XOR instructions. For an example of using XOR, AND and OR see AndOrXorBasic.asm on the class web site. main function In the main function you should have a while loop that will keep iterating until you have processed all the data in the inputA, inputB and carryin arrays. SeeDisplayByteArray.asm on the class web site for an example of iterating through a byte array. Each time through this loop you will call the Adder function to add up 3 bits (input A, input B and a carryin). Each time through the loop you have to access the data in the inputA, inputB and carryin arrays to print the data and to pass the data to the Adder function which will add up the bits and produce a sum and a carryout using a full adder simulation. To access the data in the inputA, inputB and carryin arrays you must use the following syntax: inputA[esi] inputB[esi] carryIn[esi] You must initialize esi to 0 and then increment it each time through the loop. The offsets in the arrays are as follows: offset [0] [1] [2] [3] [4] [5] [6] [7] inputA 0 0 0 0 1 1 1 1 inputB 0 0 1 1 0 0 1 1 carryin 0 1 0 1 0 1 0 1 The above arrays are parallel arrays. It is like an excel spreadsheet where each column of the spreadsheet are the inputs to the Adder function. The data at offset 0 in the three arrays is 0 for inputA, 0 for inputB and 0 for the carryin. The data at offset 1 in the three arrays is 0 for inputA, 0 for inputB and 1 for the carryin etc. The offset should start at 0, because the first data is at offset 0 from the beginning of the arrays. Then if you increment esi to 1 then 1 would be the offset to the second element of the arrays. When you are done you would have processed the data for 8 Adders as follows: (A = inputA, B = inputB, C=carryin, S = sum, CO = carryout) A B C S CO 1. 0 + 0 + 0 = 0 0 (1st iteration of loop in main) 2. 0 + 0 + 1 = 1 0 (2nd iteration of loop in main) 3. 0 + 1 + 0 = 1 0 (3rd iteration of loop in main) 4. 0 + 1 + 1 = 0 1 (4th iteration of loop in main) 5. 1 + 0 + 0 = 1 0 (5th iteration of loop in main) 6. 1 + 0 + 1 = 0 1 (6th iteration of loop in main) 7. 1 + 1 + 0 = 0 1 (7th iteration of loop in main) 8. 1 + 1 + 1 = 1 1 (8th iteration of loop in main) Each time through the loop you will print the input data to the Adder and the output from the Adder as follows: (The following is for iteration 1 of the loop. The data will change for each iteration) (You should use WriteDec to print out the digits) Input A: 0 Input B: 0 Carry in: 0 ------------ Sum: 0 Carry Out: 0 If you wish to move a value from the array to a 32 bit register you must use movzx since the arrays are byte arrays. You should write your main function to produce the output as shown in the sample output section below. Adder function To write the Adder function you should simulate the following Adder circuit using the XOR, OR and AND instructions. For an example of using XOR, AND and OR see AndOrXorBasic.asm on the class web site. Inputs to the adder function should be in EAX (input A), EBX (input B) and ECX (carryin). Do not access the arrays in main directly in the Adder function. The data must be passed into this function via the required registers. Outputs from the adder function should be in EAX (sum) and ECX (carryout). To help you plan your code you should write on the adder.pdf hand out a line of code for each gate above plus code to make sure you do not overwrite input values or intermediate results especially if the result of a calculation or input are needed in 2 different places. You will also need code to save (push) and restore (pop) any registers changed except registers that return a value (EAX and ECX). Note: the Adder function does not do any output. All the output is done in the main function. prog4SP18Student.asm prog4SP18Student.asm contains templates for the main and Adder functions. You are to add code to the given file to complete the main and Adder functions. prog4SP18Student.asm also contains variable declarations for the arrays and various strings. Do not change the given data except you made add LFs to the strings for line spacing. But do not change anything between the quotes. Do not change any data in the inputA, inputB and carryin arrays. You should use the mPrtStr macro to print strings. Do not use any other macros in your code unless directed otherwise or unless you ask first. Checking answers It is up to you to make sure the output is correct for the inputs to the Adder function per the comment block for the Adder function. Comments You should add the main comment block to the top of the file. As usual every line of code should be commented. Do not delete the comment block before the function. Every function should have a comment block before it describing the function. Submission (no output file required) Email the instructor the file you downloaded from the website after you have completed it (prog4SP18Student.asm). (output example on next page) (EAX) (EBX) (ECX) (EAX) (ECX) Output Sample output is below. (Notice where the blank lines are)(Substitute your name for my name otherwise your output must match mine exactly. I will be using a comparison program to match your output to mine so the output must match mine exactly including spaces and blank lines). The blank lines are indicated by the yellow lines below. Do not print the yellow! Program 4 by Fred Kennedy ------------ Testing Adder ------------ Input A: 0 Input B: 0 Carry in: 0 ------------ Sum: 0 Carry Out: 0 Input A: 0 Input B: 0 Carry in: 1 ------------ Sum: 1 Carry Out: 0 Input A: 0 Input B: 1 Carry in: 0 ------------ Sum: 1 Carry Out: 0 Input A: 0 Input B: 1 Carry in: 1 ------------ Sum: 0 Carry Out: 1 Input A: 1 Input B: 0 Carry in: 0 ------------ Sum: 1 Carry Out: 0 Input A: 1 Input B: 0 Carry in: 1 ------------ Sum: 0 Carry Out: 1 Input A: 1 Input B: 1 Carry in: 0 ------------ Sum: 0 Carry Out: 1 Input A: 1 Input B: 1 Carry in: 1 ------------ Sum: 1 Carry Out: 1 Hit any key to exit! Submission Submit prog4SP18Student.asm as an email attachment. Do not change the file name.

Code so far:

;Insert main comment block here .386 ;identifies minimum CPU for this program .MODEL flat,stdcall ;flat - protected mode program ;stdcall - enables calling of MS_windows programs ;allocate memory for stack ;(default stack size for 32 bit implementation is 1MB without .STACK directive ; - default works for most situations) .STACK 4096 ;allocate 4096 bytes (1000h) for stack ;Irvine32.lib contains the code for DumpRegs and many other Irvine ;functions ;*******************MACROS******************************** ;mPrtStr ;usage: mPrtStr nameOfString ;ie to display a 0 terminated string named message say: ;mPrtStr message ;Macro definition of mPrtStr. Wherever mPrtStr appears in the code ;it will be replaced with mPrtStr MACRO arg1 ;arg1 is replaced by the name of string to be displayed push edx mov edx, offset arg1 ;address of str to display should be in dx call WriteString ;display 0 terminated string pop edx ENDM ;*************************PROTOTYPES***************************** ExitProcess PROTO, dwExitCode:DWORD ;from Win32 api not Irvine to exit to dos with exit code WriteDec PROTO ;Irvine code to write number stored in eax ;to console in decimal ReadChar PROTO ;Irvine code for getting a single char from keyboard ;Character is stored in the al register. ;Can be used to pause program execution until key is hit. WriteChar PROTO ;write the character in al to the console WriteString PROTO ;Irvine code to write null-terminated string to output ;EDX points to string ;************************ Constants *************************** LF equ 0Ah ; ASCII Line Feed ;************************DATA SEGMENT*************************** .data inputAnum byte 0,0,0,0,1,1,1,1 inputBnum byte 0,0,1,1,0,0,1,1 carryInNum byte 0,1,0,1,0,1,0,1 ARRAY_SIZE equ $-carryInNum ;The '$' acts as a place maker where you are currently in memory ;which at the end of the carryInNum array. ;The ending address of the carryInNum array minus the beginning ;address equals the total bytes of the carryInNum array ;which is stored in the ARRAY_SIZE constant. ;NOTE: there can be no other variables between the ;declation of the ARRAY_SIZE constant and the declaration ;of the array you are trying to calculate the size of. ;You can add LFs to the strings below for proper output line spacing ;but do not change anything between the quotes "do not change". ;I will be using a comparison program to compare your output to mine and ;the spacing must match exactly. endingMsg byte "Hit any key to exit!",0 ;Change my name to your name titleMsg byte "Program 4 by Fred Kennedy",LF,0 testingAdderMsg byte " Testing Adder",0 inputA byte " Input A: ",0 inputB byte " Input B: ",0 carryin byte " Carry in: ",0 sum byte " Sum: ",0 carryout byte " Carry Out: ",0 dashes byte " ------------",0 ;************************CODE SEGMENT**************************** .code main PROC ;write code for main function here. See the program specifications ;pdf on the class web site for more info. main ENDP ;************** Adder  Simulate a full Adder circuit ; Adder will simulate a full Adder circuit that will add together ; 3 input bits and output a sum bit and a carry bit ; ; Each input and output represents one bit. ; ; Note: do not access the arrays in main directly in the Adder function. ; The data must be passed into this function via the required registers below. ; ; ENTRY - EAX = input bit A ; EBX = input bit B ; ECX = Cin (carry in bit) ; EXIT - EAX = sum bit ; ECX = carry out bit ; REGS - (list registers you use) ; ; For the inputs in the input columns you should get the ; outputs in the output columns below: ; ; input output ; eax ebx ecx = eax ecx ; A + B + Cin = Sum Cout ; 0 + 0 + 0 = 0 0 ; 0 + 0 + 1 = 1 0 ; 0 + 1 + 0 = 1 0 ; 0 + 1 + 1 = 0 1 ; 1 + 0 + 0 = 1 0 ; 1 + 0 + 1 = 0 1 ; 1 + 1 + 0 = 0 1 ; 1 + 1 + 1 = 1 1 ; ; Note: the Adder function does not do any output. ; All the output is done in the main function. ; ;Do not change the name of the Adder function. ; ;See additional specifications for the Adder function on the ;class web site. ; ;You should use AND, OR and XOR to simulate the full adder circuit. ; ;You should save any registers whose values change in this function ;using push and restore them with pop. ; ;The saving of the registers should ;be done at the top of the function and the restoring should be done at ;the bottom of the function. ; ;Note: do not save any registers that return a value (ecx and eax). ; ;Each line of the Adder function must be commented and you must use the ;usual indentation and formating like in the main function. ; ;Don't forget the "ret" instruction at the end of the function ; ;Do not delete this comment block. Every function should have ;a comment block before it describing the function. FA16 Adder proc ;Write code for the "Adder" procedure here. Adder endp END main 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions