Wednesday, September 30, 2015

Day 2: A Primer on Debugging & Assembly

I'm going to separate my status from the notes and stuff learned, so I can pump these logs out in a more efficient matter.

Casey-isms

  • Everything in computers is just numbers.
  • As a general theme of Handmade Hero, we want to know what the machine is doing.
  • It gives us a connection to the computer and is not that much more slower or complicated.

OutputDebugStringA() vs OutputDebugStringW()

  • What does the A stand for?
    • Windows used to work only with standard ASCII strings (or ANSI?)
    • But the ASCII system didn't work for languages like Chinese, so Unicode became the standard, so Windows had to expand
    • So Windows started using wide character strings called UTF-16

Debugging & the Breakpoint

  • You set a "breakpoint" and run code, but when program reaches this point, it stops!
    • It will freeze everything, the memory, variables, etc so i can look at it
    • Press F9 in VS to set a breakpoint
  • Breakpoint freezes RIGHT before the line that executes
  • Step Into and Step Over
    • Step Over, F10, do whatever's on the current line
    • Step Into, not covered just yet
  • Useful Debug Windows
    • Watch: type in the name of something we want to see and show up corresponding value
    • Registers: to see the assembly language CPU operates on

Assembly

  • Appears to read right to left!
  • This is important, BECAUSE WE ALWAYS WANT TO KNOW WHAT IS HAPPENING ON THE MACHINE
    • In VS, Right click and select goto disassembly
    • For debugging, bring up registers. you can right click and display in hexadecimal
011A1BCE                    mov                                  byteptr [Test], 0FFh
(location in memory)    (register mnemonic)        (moves FF in code into byte pointer )

  • By watching the registers, we know this is a memory to memory move and does not reach the  registers)
  • Hexadecimal notations 
    • VS will translate it for you if you hover over hex
    • 0FFh : Assembly Notation
    • 0xFF (0xcc) : C notation

  • Even though EAX can hold 0000 0000, we can reference smaller parts of a register. we can pull out the bottom 8 bits...
    • This is what "al" (references to EAX to pull only a byte) does!


No comments:

Post a Comment