Question

In: Computer Science

X86 Assembly MASM Questions below ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the...

X86 Assembly MASM

Questions below

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; Answer each question below by writing code at the APPROPRIATE places at the end
;;;;; of the file as indicated.

;;;;; Q2: Write the directive to bring in the IO library          

;;;;; Q3: Create a constant called DAYS_PER_WEEK and initialize it to 5
;;;;;     Create a constant called WEEKS_PER_YEAR and initialize it to 49

;;;;; Q4: Create a constant called DAYS_PER_YEAR by using DAYS_PER_WEEK and
;;;;;     WEEKS_PER_YEAR (of Q3) in an integer expression constant

;;;;; Q5: Define an array of 10 signed doublewords, use any array name you like.
;;;;;     Initialize:
;;;;;   - the 1st element to the DAYS_PER_YEAR value defined in Q4
;;;;;   - the 2nd element to the hexadecimal value: B285
;;;;;   - the 3rd element to the 4-bit binary value: 1001
;;;;;   - the 4th element to the decimal value: -250
;;;;; and leave the rest of the array uninitialized.

;;;;; Q6. Define the string "Output = ", use any variable name you like.

;;;;; Q7. Define a prompt that asks the user for a negative number

;;;;; Q8. Write code to prompt the user for a number, using the prompt string that
;;;;;     you defined in Q7

;;;;; Q9. Write code to read in the user input, which is guaranteed to be negative

;;;;; Q10. Write code to print "Output = " and then print to screen the user input
;;;;;       which should be a negative value

;;;;; Q12. Write code to print "Output = " and then print the first element of the
;;;;;      array defined in Q5, without the + symbol in front.

;;;;; Q13. Build, run, and debug your code
;;;;; Your output should be similar to this (without the commented explanation)

;;;;; Enter a negative number: -10
;;;;; Output = -10                          
;;;;; Output = 245                          
;;;;; Press any key to continue . . .

;;;;; Q14. At the end of the source file, without using semicolons (;), add a comment
;;;;;      block to show:
;;;;;       - how bigData appears in memory. You should copy from the debugger memory
;;;;;        window and it should be the same 8 bytes as in lab 2)
;;;;;      - note that the 8 bytes in memory doesn't look identical to the 8 bytes
;;;;;        that are used to define bigData. Explain why the 8-byte sequence
;;;;;        are different

;;;;; 1pt EC (Extra Credit):
;;;;; In the same comment block, explain how many bytes the array of Q5 occupy
;;;;; in memory.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;   Put your answers below this line

.data
bigData QWORD 9876543210fedcbah       ; same bigData value as lab 2


.code
main PROC


   exit  
main ENDP

END main

Solutions

Expert Solution

part 1
section .text
   global _start          ;must be declared for linker (gcc)
        
_start:                   ;tell linker entry point
   mov  edx,1             ;message length
   mov  ecx,choice        ;message to write
   mov  ebx,1             ;file descriptor (stdout)
   mov  eax,4             ;system call number (sys_write)
   int  0x80              ;call kernel

   mov  eax,1             ;system call number (sys_exit)
   int  0x80              ;call kernel

section .data     ;variable declaration start here

part 2

DAYS_PER_WEEK DB 5 ;DB=Define Byte allocates 1 byte

WEEKS_PER_YEAR DB 9

part3

MOV AL ,DAYS_PER_WEEK ;load variable to AL

MOV BL,WEEKS_PER_YEAR ;;load variable to BL

MUL BL                        ;multiplication

MOV DAYS_PER_YEAR ,AL ;move result to days_per_year

part 4

;for 1001 hex is 9 and for -250 decimat to hex is -FA

array1   DW  DAYS_PER_YEAR , B285 , 9 , -FA , 0 , 0 , 0 , 0,0,0

Related Solutions

Please complete in MASM (x86 assembly language). Use the code below to get started. Use a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a loop with indirect or indexed addressing to reverse the elements of an integer array in place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future. .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your...
Hi this is Assembly Language MASM x86 program. Please write it in the language and please...
Hi this is Assembly Language MASM x86 program. Please write it in the language and please explain it with comments thank you Please answer it I really need help this question was refunded before so please answer. Thank you so much also these are two separate programs thank you. 1) Write a procedure to read in decimal or hex number (byte-sized) Then write a procedure using shifts and ANDS to convert the string to a binary number (if is backward,...
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2,...
Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2, and num3 and display the value of the expression ( (num1 ^ 3) * num2 + 5 * ( num2 ^ 2) ) / num3. assume that the user enters only numbers that are greater than zero and the calculation never exceed 4 bytes size. Sample run: num1 = 1 num2 = 2 num3 = 3 ((num1 ^ 3) * num2 + 5 *...
Using x86 assembly language, create a flowchart and write an example of code that will sort...
Using x86 assembly language, create a flowchart and write an example of code that will sort 2 arrays of unsigned doubleword integers in ascending order and output the largest element in each array. Any sorting procedure can be used, but this procedure must be called twice for each array. The first time it is called, the first array should be sorted and the second time it is called, the second array must be sorted. As well as outputting which is...
PLEASE ANSWER THE QUESTIONS BELOW according to international accounting Question 1,2,3,4,12,13 should be prepared in writing...
PLEASE ANSWER THE QUESTIONS BELOW according to international accounting Question 1,2,3,4,12,13 should be prepared in writing Discuss four stages of financial statement analysis. Why at each step is analysis in a cross-border context more difficult than in a single-country? Discuss special issues that you think important in analyzing financial statements of foreign companies. Discuss possible adjustable and non-adjustable differences in international financial statement analysis. How will you make general assessment of a countries accounting quality? Discuss general structure of form...
Answer the questions below and each question has a part to complete required for that question...
Answer the questions below and each question has a part to complete required for that question You have been contracted by the government of your country to provide recommendations on the regulation of the national textile industry. Currently, the textile industry which resembles features of the perfectly competitive market is completely unregulated. Using the concepts covered in the class, please provide your advice to the problems below. One of the biggest social problems in the textile industry is child labour...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
Answer two questions from the three below (750 words each question). Questions are: - In what...
Answer two questions from the three below (750 words each question). Questions are: - In what ways does the media misrepresent the nature of crime? - Violent crime can be a source of concern, but is it the most frequently occurring type of crime in society? - Is the risk of being a victim of violent crime evenly distributed throughout society? Exam responses will be in essay format and approximately 750 words each.
Question 3. In the following code, answer these questions: Analyze the code and how it works?...
Question 3. In the following code, answer these questions: Analyze the code and how it works? How can we know if this code has been overwritten? Justify how? #include <stdlib.h> #include <unistd.h> #include <stdio.h> int main(int argc, char **argv) { int changed = 0; char buff[8]; while (changed == 0){ gets(buff); if (changed !=0){ break;} else{     printf("Enter again: ");     continue; } }      printf("the 'changed' variable is modified\n %d", changed); } END of the questions :::::::::::::::::::::::::: :::::::::::::::::::::::::: Submission...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT