Computer Organization and Assembly Language (CS2411 & CSC2201)
Computer Organization and Assembly Language (CS2411 & CSC2201)
Computer Organization and Assembly Language (CS2411 & CSC2201)
val1 BYTE 10
All initializers become binary data in memory
Above example declares variable having name ‘val1’ of size Byte/8bits and
assigns value 10.
• MASM does not prevent you from initializing a BYTE with a negative value, but it's considered poor style.
• If you declare a SBYTE variable, the Microsoft debugger will automatically display its value in decimal with a leading
sign.
Szabist Larkana Campus 6
Adding a Variable to the AddTwo Program
(Lab Work)
; AddTwoSum.asm - Chapter 3 example
.386
.model flat, stdcall
.stack 4096
.data
sum DWORD 0 Variable name “sum” of type double word having value 0
.code
main PROC
mov eax, 5
add eax, 6
mov sum, eax Moving data value from eax register to variable sum
main ENDP
END main
The x86 instruction set does not let us add one variable directly to another (sum1+sum2 => ADD
sum1, sum2).
But, it does allow a variable to be added to a register (SUM1+EAX => ADD EAX, SUM1).
To continue the array of bytes begun with list, we can define additional bytes on
the next lines:
Example:
list BYTE 10,20,30,40
BYTE 50,60,70,80
BYTE 81,82,83,84
main ENDP
END main
Szabist Larkana Campus 13
DUP Operator
Allocates storage for multiple data items using a integer expression.
Likewise a counter.
It is particularly useful when allocating space for a string or array.
can be used with initialized or uninitialized data:
Examples
Var1 BYTE 20 DUP(0) ; 20 bytes, all equal to zero
var2 BYTE 20 DUP(?) ; 20 bytes, uninitialized
var3 BYTE 4 DUP("STACK") ; 20 bytes: "STACKSTACKSTACKSTACK"
The WORD (define word) and SWORD (define signed word) directives
create storage for one or more 16-bit integers.
word1 WORD 65535 ; largest unsigned value
word2 SWORD -32768 ; smallest signed value
word3 WORD ? ; uninitialized, unsigned
PI EQU <3.1416>
Examples
matrix1 EQU 10 * 10
matrix2 EQU <10 * 10>
.data
M1 WORD matrix1 M1 WORD 100
M2 WORD matrix2 M2 WORD 10 * 10
Szabist Larkana Campus 18
TEXTEQU Directive
EXAMPLE
rowSize = 5
count TEXTEQU %(rowSize * 2)
move TEXTEQU <mov>
setupAL TEXTEQU <move al,count>
.386
.model flat, stdcall
.stack
include irvine32.inc
.data
list1 BYTE 10,20,30,40
listSize = ($-list1)
.code
main PROC
mov ax, listSize
call DumpRegs
main ENDP
END main