Names

10
Names Identifi er name you apply to items in your program. Types : name (refers to the address of a data item ) label (refers to the address of an instruction ) Statemen t program is made of a set of statements. Types: instructions: e.g. (MOV and LEA) directives: tell the assembler to perform a specific action like ".model small" Here's the general format of a statement: indentifier - operation - operand(s) - comment The identifier is the name as explained above. The operation is an instruction like MOV. The operands provide information for the Operation to act on. Like MOV (operatio The comment is a line of text you can add as a comment, everything the assemble E.g. MOVINSTRUCTION: MOV AX,BX ;this is a MOV instruction

description

Names. Here's the general format of a statement: indentifier - operation - operand(s) - comment - PowerPoint PPT Presentation

Transcript of Names

Page 1: Names

Names Identifier name you apply to items in your program.

Types :

name (refers to the address of a data item )

label (refers to the address of an instruction )

Statement program is made of a set of statements. Types:

instructions: e.g. (MOV and LEA)

directives: tell the assembler to perform a specific action like ".model small"

Here's the general format of a statement: indentifier - operation - operand(s) - comment The identifier is the name as explained above.The operation is an instruction like MOV.The operands provide information for the Operation to act on. Like MOV (operation) AX,BX (operands).The comment is a line of text you can add as a comment, everything the assembler sees after a ";“

E.g. MOVINSTRUCTION: MOV AX,BX ;this is a MOV instruction

Page 2: Names

Jump statements

• Simplest form of Jump statement– “jmp Lable”

• Equivalent to GOTO• Simply says: Jump to Label

Page 3: Names

Equality Comparison

• CMP leftOp, rightOP• Compares the leftOperand to the

rightOperand• Jumps based on Equality:

– JE (jump if equal)– JNE (jump if not equal)– JCXZ (jump if CX = 0)– JECXZ (jump if ECX = 0)

Page 4: Names

IF ELSE’s

If (Expression)

Statement List 1

Else

Statement List 2

start

expression

Statement List 1

Statement list 2

end

FALSETRUE

Page 5: Names

IF ELSE’s

If (OP1 == OP2){

X = 1;

Y = 2;

}

Else {

Z = 1;

}

Initial code here

Cmp op1 op2

L3:

Je L1

L1:Mov X,1Mov Y,2Jmp L3

L2:Mov Z, 1Jmp L3

Page 6: Names

Branching • Conditional jump

Assembly C/C++/Java Equivalent

cmp ax, bx

jg isgreater

:

: ; block 1 (else part)

:

jmp after

isgreater:

:

: ; block 2 (then part)

:

after:

: ; after if

:

if (ax > bx)

{

// block 2

}

else

{

// block 1

}

// after if

Page 7: Names

Branching [cont…]

Instruction Meaningjg Jump if greater

jge Jump if greater or equal

jl Jump if less

jle Jump if less or equal

je Jump if equal

jne Jump if not equal

jc Jump if carry flag is set

Page 8: Names

While Loops

While (Expression)

Statement List

TRUE

start

Expression

Statement List

End

FALSE

Page 9: Names

Loops [continue]• .code stack100h • jmp start

• start: mov cx, 10 ; The counter is in CX • mov ax, 0 ; I use AX as a sum holder • myloop: • add ax, cx ; ax = ax + cx • loop myloop

• quit: ; here ax will hold the value of 1+2+...+10 • mov ax, 4c00h • int 21h • end

Page 10: Names

Prac 3

• Write an Assembly Program that:– prompts the user for a System Administrator pin (PIN). – prompts the user for an Iteration Limit (LIMIT). – prints "---THE SYSTEM IS NOW RUNNING---" – Loop until counter = LIMIT

• prompt user for pin• if pin == PIN, jump to CORRECT PIN handling code • else print error message and increment counter • jump back to beginning of loop.

Save as your program as “access.asm” Correction email: [email protected]