Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
This week:
1. Project requirements
2. Revision
3. Sample code
4. Lab assignment
Assignment
Contributes 20% of your total coursework marks.
32 bit or 16 bit.
Number of assignment: 4
Each assignment contributes 5% marks.
Each assignment must be demo in the lab
session.
Report and the written code.
2 students per group for each assignment.
1st assignment: in the end of this lab session.
Revision
Basic Elements of Assembly Language.
Adding and Subtracting Integers example
of code
Integer Constants
Optional leading +or sign
binary, decimal, hexadecimal, or octal digits
Common radix characters:
h hexadecimal
d decimal
b binary
r encoded real
q/o - octal
If no radix: decimal
Integer Expressions
Operators and precedence levels:
Examples:
Embedded quotes:
'Say "Goodnight," Gracie'
Reserved Words
Reserved words (Appendix D) cannot be used as identifiers
Directives
command understood by the assembler
not part of Intel instruction set
case insensitive
Identifiers
Identifiers (programmer-chosen name)
May contain 1-247 characters, including digits
Not case-sensitive (by default)
first character must be a letter (A..Z,a..z), _, @, ? or $
Subsequent character may also be a digit
Identifier cannot be the same as assembler reserved word.
Avoid using single @ sign as first character.
Ex : Valid identifier
Var1, Count, MAX, $first, open_file, _12345, @@myfile,_main
common sense create identifier names that easy to understand
Directives
Commands that are recognized / understood and acted upon
by the assembler
Not part of the Intel instruction set
Used to declare code, data areas, select memory model, declare
procedures, etc.
Not case sensitive (.data, .DATA, .Data - same)
Examples :
.DATA identify area of a program that contains variables
.CODE identify area of a program that contains instructions
PROC identify beginning of a procedure. name PROC
Instructions
Assembled into machine code by assembler
Executed at runtime by the CPU after the program has been
loaded into memory and started.
Member of the Intel IA-32 instruction set
Parts :
A) Label (optional)
B) Mnemonic (required)
C) Operand (required)
D) Comment (optional)
Label :
Mnemonics
Operand(s)
; Comment
A) Labels
Act as place marker marks the address (offset) of code
and data
Follow identifier rules (refer slide pg 8)
Data label
must be unique
example: myArray
mov ax, myVariable
Code label
target of jump and loop instructions target :
mov ax,bx
example: L1:
jmp target
C) Operands
An assembly language can have between zero to three
operands
Types of operand :
constant (immediate value)
96, 2005h, 101011010b
constant expression
2+4
register
EAX, EBX, AX, AH
.. C) Operands
Examples assembly language instructions with various
number of operands :
No operand
stc
; set carry flag
one operand
inc ax
; add 1 to AX
two operand
mov count, bx
; move BX to count
D) Comments
Comments are good.
explain the program's purpose
when it was written, and by whom
revision information
tricky coding techniques
application-specific explanations
Single-line comments
begin with semicolon (;)
Ex :
; add BX to AX
Multi-line comments
begin with COMMENT directive and a programmer-chosen character
end with the same programmer-chosen character
Ex :
COMMENT !
This is a comment
This line is also a comment
Comment lagi dan lagi dan lagi.
Lepas ni habis ekk
!
(pokai.asm)
INCLUDE Irvine32.inc
.data
(insert variables here)
val1
dword 10000h
.code
main PROC
(insert executable instructions here)
mov ax,@data
; initialize DS
exit
; exit to operating system
main ENDP
(insert additional procedures here)
END main
(AddSub.asm)
INCLUDE Irvine32.inc
.code
main PROC
mov eax,10000h
add eax,40000h
sub eax,20000h
call DumpRegs
exit
main ENDP
END main
;
;
;
;
EAX = 10000h
EAX = 50000h
EAX = 30000h
display registers
mov eax,10000h
EAX
0010 0000
EAX
0050 0000
10000 h + 40000 h
= 50000 h
EAX
0030 0000
50000 h 20000 h
= 30000 h
10000 h
add eax,40000h
sub eax,10000h
19
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
Other suggestions
descriptive identifier names
spaces surrounding arithmetic operators
blank lines between procedures
Sample
TITLE Add and Subtract
(AddSubAlt.asm)
.code
main PROC
mov eax,10000h
add eax,40000h
sub eax,20000h
call DumpRegs
INVOKE ExitProcess,0
main ENDP
END main
; EAX = 10000h
; EAX = 50000h
; EAX = 30000h
Program Template
TITLE Program Template
(Template.asm)
;
;
;
;
;
INCLUDE Irvine32.inc
.data
; (insert variables here)
.code
main PROC
; (insert executable instructions here)
exit
main ENDP
; (insert additional procedures here)
END main
Program Description:
Author:
Creation Date:
Revisions:
Date:
Modified by:
Instruction: please
customize as needed
Assignment 1
Write a program MASM assembly langguage to have the input
and output as follows:
Input:
Assignment 1
Output:
. Assignment 1
Due date: 2 weeks from now.
18 March 2014.
Demo in the lab.
Write a simple report with a code of the
program.
2 students per group.