2nd Lecture
2nd Lecture
&
ASSEMBLY LANGUAGE
⦿ Examples:
Character and String Constants
⦿ Embedded quotes:
› 'Say "Goodnight," Gracie'
Reserved Words and Identifiers
INCLUDE Irvine32.inc
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs ; display registers
exit
main ENDP
END main
Example Output
Program output, showing registers and flags:
Idea: Define all strings used by your program in the same area of the data
segment.
Using the DUP Operator
⦿ Use DUP to allocate (create space for) an array or
string.
⦿ Counter and argument must be constants or
constant expressions
⦿ Example:
val1 DWORD 12345678h
Adding Variables to AddSub
TITLE Add and Subtract, Version 2 (AddSub2.asm)
; This program adds and subtracts 32-bit unsigned
; integers and stores the sum in a variable.
INCLUDE Irvine32.inc
.data
val1 DWORD 10000h
val2 DWORD 40000h
val3 DWORD 20000h
finalVal DWORD ?
.code
main PROC
mov eax,val1 ; start with 10000h
add eax,val2 ; add 40000h
sub eax,val3 ; subtract 20000h
mov finalVal,eax ; store the result (30000h)
call DumpRegs ; display the registers
exit
main ENDP
END main
Declaring Unitialized Data
⦿ Use the .data? directive to declare an
unintialized data segment:
.data?
⦿ Within the segment, declare variables with "?"
initializers:
smallArray DWORD 10 DUP(?)
⦿ name = expression
› expression is a 32-bit integer (expression or constant)
› may be redefined
› name is called a symbolic constant
⦿ good programming style to use symbols
COUNT = 500
.
.
mov al,COUNT
Calculating the Size of a Byte
Array
⦿ current location counter: $
› subtract address of list
› difference is the number of bytes
PI EQU <3.1416>
pressKey EQU <"Press any key to continue...",0>
.data
prompt BYTE pressKey
TEXTEQU Directive
⦿ Define a symbol as either an integer or text expression.
⦿ Called a text macro
⦿ Can be redefined