In: Computer Science
MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO
You will write a simple assembly language program that performs a few arithmetic operations. This will require you to establish your programming environment and create the capability to assemble and execute the assembly programs that are part of this course.
Your \student ID number is a 7-digit number. Begin by splitting your student ID into two different values. Assign the three most significant digits to a variable called 'left' and the four least significant digits to a variable called 'right'.
You must choose the data type that is appropriate for the range of decimal values each variable can store. You will choose a data type when you define each of the variables in your program. Try to make efficient use of memory.
Calculate the sum of the two variables 'left' and 'right'. Store this result in a variable called 'total'.
Calculate the positive difference between the variables 'left' and 'right'. Store this result in a variable called 'diff'.
Define a character string called 'message' that contains the characters, "Hello world!".
Define an array of data type WORD called 'Array' that is initialized to the following values: 1, 2, 4, 8, 16, 32, and 64.
Write assembly language code using what you know so far (do not look ahead in the book just yet) to determine the length of 'Array'. Store this value in a variable called 'ArrayLength'.
Move the contents of the variable 'left' into the EAX register.
Move the contents of the variable 'right' into the EBX register.
Move the contents of the variable 'total' into the ECX register.
Move the contents of the variable 'diff' into the EDX register.
Move the contents of the variable 'ArrayLength' into the ESI register.
Call the author's DumpReg routine to display the contents of the registers.
MOV ID,#1234567h #input from user
MOV B,#10000h
MOV C,ID MOD B
DIV ID,B
MOV LEFT,ID #Moves 3 most significant bits into left
MOV RIGHT,C # Moves 4 least significant bits into right
MOV EAX,LEFT #moves left value into EAX register
MOV EBX,RIGHT #moves right value into EBX register
ADD LEFT,RIGHT #adds left and right bits
MOV SUM,LEFT #moves addtion value into SUM variable
MOV ECX,SUM #moves SUM variable into ECX register
SUBB RIGHT,LEFT #finds difference between left and right
MOV DIFF,RIGHT #shifts diffenece into DIFF variable
MOV EDX,DIFF #moves DIFF variable into EDX register
MESSAGE DB 10, 13, ‘HELLO WORLD $’ # declaring string
A WORD 1, 2, 4,8,16,32,64 #declaring an array
ListSize = ($ - A) #finding size of an array
MOV ARRAYLENGTH,ListSize # moving size value into ARRAYLENGTH variable
MOV ESI,ARRAYLENGTH #moving ARRAYLENGTH variable into ESI register
Call DumpReg #calling DumpReg to display the contents of the register