Memory and Integer Arithmetic due Thu 13 Sep 14:45

In this assignment you will learn/practice several significant ...
...el assembly documentation
\item addressing modes

Preparation for Lab Day

Suppose the following declarations start at address 01B0h. As we did in class write in hex on a byte-by-byte basis the address and value of each byte generated by these NASM instructions. Also include the labels.
                section .data
int:            dd      68,-9
floaty:         dd      -68.125
char:           db      "Greetings!",10,0
bighex:         dq      10h
mediumbin:      dw      10b

                section .bss
somememory:     resd    2

                ; you can actually have multiple of these sections interleaved if you want to
                ; but generally that would just be confusing!

                section .data
nightnight:     db      "ZZZZZZZZ"

Bring your hand-written solution to lab day.

Lab Day

  1. At the beginning of the period show your prep work to the instructor.

  2. NOTE: The following instructions assume you are doing all of your work (homework and labday work) on and that the al_homework repository on that server is up-to-date. If this is not the case you'll need to thoughtfully manage the following instructions when they ask you do perform git commands.

    Start by making sure your local (on repository has the most recent files from the course homework repository.

  3. Observe that the repository provides the following:
    • Some macros that will enable relatively convenient I/O (see lib directory).
    • Some programs to demonstrate the macros (see demos directory).
    • A reasonably sane .gitignore file.
    • Some data files for possible future use (see data directory).
    • Initial directories for labday files and homework files.

  4. The file dumpregs.asm (in lib) contains macros that will be very helpful in debugging programs this semester. It contains a command called dump_regs that will show (in hex) the values of the registers. In the ld01 directory write an assembly program that uses the %include directive to include ../lib/dumpregs.asm. Move the number 10 to r8 and then call dump_regs and inspect the output.

  5. Now modify your program so that it encodes the NASM memory declarations from the pre-lab assignment. Observe the output of these commands:
    	mov r8,int
    	mov r9,floaty
    	mov r10,[int]
    	mov r11,[floaty]

    If you subtract r8 from r9 (by hand) what do you get? Why? Ponder the output until you understand it.

  6. Move the memory starting at label int into registers. Do not use rbp or rsp. After you've copied the memory into the registers, call dump_regs to show the memory contents. Compare the output of the program with your hand-written solution and reconcile any differences. One simple way to do this is:
    	mov rax,[int]    ; moves 8 bytes at int into rax
    	mov rbx,[int+8]  ; moves 8 bytes at int+8 into rbx
    	mov rcx,[int+16] ; etc.

  7. What happens if you continue to print memory past the end of your memory declarations? Try it.

  8. Prior to moving memory contents into registers issue this command so you will be able to see where the label somememory starts: mov qword [somememory],0x33333333 After you see the effect of this command, remove the word qword from it and re-compile. Why is qword required for this mov command but not for any of the other mov commands in this program?

  9. Take a moment to commit your work and push the changes to bitbucket.

  10. Show your work to the instructor and describe any mistakes you may have made when creating your hand-written memory map.

  11. If you finish early, work on your homework assignment until the end of the lab period.

Quick Links