150 likes | 244 Views
Target Processor Directives. .8086----8086, 8088 .186--- .286--- .386 .486 .586 .287 .387 When using .386, the program can only run on 386 and above processors. Operators and Expressions. 1. Arithmetic Operators most of them only works with integers.
E N D
Target Processor Directives • .8086----8086, 8088 • .186--- • .286--- • .386 • .486 • .586 • .287 • .387 • When using .386, the program can only run on 386 and above processors.
Operators and Expressions • 1. Arithmetic Operators most of them only works with integers. • Exceptions: + and – can be used on real #s • 1000 * 50h • -4 + -2 • Count + 2 ; • 31 MOD 6 ; 1 • 6/4 ; 1 • ‘2’ – 30h ; 2
Assembler Operators • There are many assembler operators. We will introduce them through practical examples. • 1. Offset operator • .data (assume its address is 0000) • count db 10h, 20h, 30h, 40h, • mov bx, offset count • (bx will have 0000h in it after the statement)
Examples • .data • blist2 db 10h, 20h, 30h, 40h • wlist2 dw 1000h, 2000h, 3000h • Mov di, offset blist2 ; DI = 0000 • Mov bx, offset blist2+1 ; BX = 0001 • Mov si, wlist2+2 ; SI = 0006 • (wlist2 has the offset address of 0004) • *** We are working on these addresses instead of the counts)
SEG Operator • Push ds • Mov ax, seg array • Mov ds, ax • Mov bx, offset array • . • . • Pop ds • *** Normally used when a variable in in a different segment than the one currently pointed by DS register
PTR---Overrides the default size of an operand • 1. It has to be used along with: • BYTE, SBYTE, WORD, SWORD, DWORD, SDWORD, FWORD, QWORD, and TBYTE ---assembler data types. • Purpose: help explicitly state the operand’s size. • inc [bx]; will confuse the assemblerwhether BX points toa byte or a word. • Inc byte ptr [bx] will make the size clear.
Examples • Mov al, byte ptr count • Mov ax, word ptr newVal • Mov eax, dword ptr listpointer ; (.386)
Even and Evendata directives • Usage insert into the code area with even (nop or 90h) to make the next instruction begins with an even number of address; • Or insert a null (0) into the data area to make data line items begin with an even number of address. • This process can improve a program’s peed by taking advantage of processors that use a 16-bits data bus.
Examples • 0000 mov ax, @data • 0003 mov ds, ax • 0005 even • 0006 mov bx, offset array • .data • 0000 str1 db 3 dup(‘X’) • 0003 evendata • 0004 array dw 10 dup(0FFFh)
Transfer of control , or branch • Normally, the CPU automatically loads and executes programs sequentially. • pc (Program counter) automatically increments to point to next instruction. • All program languages contain transfer of control functions. • 1. Unconditional transfer • 2. Conditional transfer
JMP Instruction • The JMP instruction yell the CPU to continue execution at another location. • Instruction format: • JMP SHORT destination • JMP NEAR PTR destination • JMP FAR PTR destination • *** In 32-bits segment:offset address, if one • jump to a different code segment, the CPU will load that segment’s address into CS register. CS:IP
Examples • Jmp L1 ; NEAR: current segment • Jmp near ptr L1 ; NEAR: current segment • Jmp short nextval ; SHORT: within –128—127 bytes • Jmp far ptr error_rtn ; FAR: to different segment • *** Structured programming style discourages suuch like goto or jumps. However, they are occationally is necessary in assembly language system programming applications. This gives us the power to jump to any RAM and ROM locations, such as BIOS.
Example • mov cx, 12*80 • next: • mov ah, 2 • mov dl, ‘a’ • int 21h • loop next • How do we do it in debug mode?
LOOPD (LOOP doubleword) • This allows a loop to execute as many as • 2 times or 4,294,967,295 times • Instead of using CX as the counter, loopd use ECX as the counter. (32-1)
Indirect Addressing • 1. Indirect operands • Look an example first, • .data • aString db “ABCDEFG” • .code • mov bx, offset aString • add bx, 5 • mov dl, [bx] [bx] A B C D E F G aString 0200 0205