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.
int: dd 68,-9
floaty: dd -68.125
char: db "Greetings!",10,0
bighex: dq 10h
mediumbin: dw 10b
somememory: resd 2
; you can actually have multiple of these sections interleaved if you want to
; but generally that would just be confusing!
nightnight: db "ZZZZZZZZ"
Bring your hand-written solution to lab day.
- At the beginning of the period show your prep work to the instructor.
- NOTE: The following instructions assume you are doing all of your work
(homework and labday work) on csci.hsutx.edu 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 csci.hsutx.edu) repository has
the most recent files from the course homework repository.
- Observe that the repository provides the following:
- Some macros that will enable relatively convenient I/O (see
- 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.
- 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
- Now modify your program so that it encodes the NASM memory declarations
from the pre-lab assignment. Observe the output of these commands:
If you subtract r8 from r9 (by hand) what do you get? Why?
Ponder the output until you understand it.
- Move the memory starting at label int into registers. Do not use
rbp or rsp. After you've copied the memory into the registers,
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.
- What happens if you continue to print memory past the end of your memory
declarations? Try it.
- 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?
- Take a moment to commit your work and push the changes to bitbucket.
- Show your work to the instructor and describe any mistakes you may have
made when creating your hand-written memory map.
- If you finish early, work on your homework assignment until the end of
the lab period.