In: Computer Science
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
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