【正文】
Labels ? Act as place markers – marks the address (offset) of code and data ? Easier to memorize and more flexible mov ax, [0020] → mov ax, val ? Follow identifier rules ? Data label – must be unique – example: myArray BYTE 10 ? Code label – target of jump and loop instructions – example: L1: mov ax, bx ... jmp L1 Mnemonics and operands ? Instruction mnemonics – reminder – examples: MOV, ADD, SUB, MUL, INC, DEC ? Operands – constant (immediate value), 96 – constant expression, 2+4 – Register, eax – memory (data label), count ? Number of operands: 0 to 3 – stc 。 set Carry flag – inc ax 。 add 1 to ax – mov count, bx 。 move BX to count Comments ? Comments are good! – explain the program39。s purpose – tricky coding techniques – applicationspecific explanations ? Singleline ments – begin with semicolon (。) ? block ments – begin with COMMENT directive and a programmerchosen character and end with the same programmerchosen character COMMENT ! This is a ment and this line is also a ment ! Example: adding/subtracting integers TITLE Add and Subtract () 。 This program adds and subtracts 32bit integers. INCLUDE .code main PROC mov eax,10000h 。 EAX = 10000h add eax,40000h 。 EAX = 50000h sub eax,20200h 。 EAX = 30000h call DumpRegs 。 display registers exit main ENDP END main directive marks ment ment copy definitions from code segment. 3 segments: code, data, stack beginning of a procedure source destination mark the last line and startup procedure defined in to end a program Example output Program output, showing registers and flags: EAX=00030000 EBX=7FFDF000 ECX=00000101 EDX=FFFFFFFF ESI=00000000 EDI=00000000 EBP=0012FFF0 ESP=0012FFC4 EIP=00401024 EFL=00000206 CF=0 SF=0 ZF=0 OF=0 Suggested coding standards (1 of 2) ? Some approaches to capitalization – capitalize nothing – capitalize everything – capitalize all reserved words, including instruction mnemonics and register names – capitalize only directives and operators (used by the book) ? Other suggestions – descriptive identifier names – spaces surrounding arithmetic operators – blank lines between procedures Suggested coding standards (2 of 2) ? Indentation and spacing – code and data labels – no indentation – executable instructions – indent 45 spaces – ments: begin at column 4045, aligned vertically – 13 spaces between instruction and its operands ? ex: mov ax,bx – 12 blank lines between procedures Alternative version of AddSub TITLE Add and Subtract () 。 This program adds and subtracts 32bit integers. .386 .MODEL flat,stdcall .STACK 4096 ExitProcess PROTO, dwExitCode:DWORD DumpRegs PROTO .code mai