Presentation is loading. Please wait.

Presentation is loading. Please wait.

Irvine, Kip R. Assembly Language For Intel-Based Computers.data string db "This is a string." COUNT = ($–string) ; calculate string length.code mov cx,COUNT.

Similar presentations


Presentation on theme: "Irvine, Kip R. Assembly Language For Intel-Based Computers.data string db "This is a string." COUNT = ($–string) ; calculate string length.code mov cx,COUNT."— Presentation transcript:

1 Irvine, Kip R. Assembly Language For Intel-Based Computers.data string db "This is a string." COUNT = ($–string) ; calculate string length.code mov cx,COUNT ; loop counter mov si,offset string L1: mov ah,2 ; DOS function: display char mov dl,[si] ; get character from array int 21h ; display it now inc si ; point to next character Loop L1 ; decrement CX, repeat until 0 Displaying a String

2 Irvine, Kip R. Assembly Language For Intel-Based Computers.data intarray dw 0100h,0200h,0300h,0400h COUNT = ($ – intarray) / (TYPE intarray).code mov ax,0 ; zero accumulator mov di,offset intarray ; address of array mov cx,COUNT ; loop counter L1: add ax,[di] ; add an integer add di,TYPE intarray ; point to next integer Loop L1 ; repeat until CX = 0 Summing an Integer Array

3 Irvine, Kip R. Assembly Language For Intel-Based Computers Based and Indexed Operands The microsoft assembler permits the same address expression to be notated in various ways:

4 Irvine, Kip R. Assembly Language For Intel-Based Computers Two-Dimensional Array Example.data ROWSIZE = 5 array db 2h, 16h, 4h, 22h, 13h db 19h, 42h, 64h, 44h, 88h.code mov bx,ROWSIZE mov al,array[bx] ; AL = 19h Each row of this table contains five bytes. BX points to the beginning of the second row:

5 Irvine, Kip R. Assembly Language For Intel-Based Computers Based-Index Operands Add the value of a base register to an index register, producing an effective address of 0157: BX = 0155, SI = 0002 Example...

6 Irvine, Kip R. Assembly Language For Intel-Based Computers.data ROWSIZE = 5 array db 10h, 20h, 30h, 40h, 50h db 60h, 70h, 80h, 90h,0A0h db 0B0h,0C0h,0D0h,0E0h,0F0h.code mov bx,offset array ; point to the array at 0150 add bx,ROWSIZE ; choose second row mov si,2 ; choose third column mov al,[bx + si] ; get the value at 0157 Base-Index Example

7 Irvine, Kip R. Assembly Language For Intel-Based Computers Base-Index with Displacement.data ROWSIZE = 5 array db 10h, 20h, 30h, 40h, 50h db 60h, 70h, 80h, 90h,0A0h db 0B0h,0C0h,0D0h,0E0h,0F0h.code mov bx,ROWSIZE ; row 1 mov si,2 ; column 2 mov dl,array[bx + si] ; DL = 80h

8 Irvine, Kip R. Assembly Language For Intel-Based Computers Debugging Workshop

9 Irvine, Kip R. Assembly Language For Intel-Based Computers 1: title Mismatching Operand Sizes 2: 3:.model small 4:.stack 100h 5:.code 6: main proc 7:mov ax,@data 8:mov ds,ax 9:mov ax,value1 10:mov ah,value2 11:mov ax,4C00h 12:int 21h 13:main endp 14: 15:.data 16: value1 db 0Ah 17: value2 dw 1000h 18: end main (9): warning A4031: Operand types must match (10): warning A4031: Operand types must match Mismatching Operand Sizes

10 Irvine, Kip R. Assembly Language For Intel-Based Computers 1: title Miscellaneous Errors Program 2: 3:.model small 4:.stack 100h 5:.code 6: main proc 7: mov ax,@data 8: mov ds,ax 9: mov ax,bx * cx 10: mov bx,value1 * 2 11: mov byte ptr value3,al 12: mov cx,ax 13: mov cs,ds 14: mov ax,4C00h 15: int 21h 16: main endp 17:.data 18: value1 db 0Ah 19: value2 db 14h 20: value3 dw 1000h 21: end main Miscellaneous Errors

11 Irvine, Kip R. Assembly Language For Intel-Based Computers Intel386 and Intel486 Instructions MOVZX - Move with zero-extend –moves 8-bit operand into a 16-bit register, fills upper bits with zeros –moves 16-bit operand into a 32-bit register, fills upper bits with zeros MOVSX - Move with sign-extend –moves 8-bit operand into a 16-bit register, sign extends into upper bits –moves 16-bit operand into a 32-bit register, sign extends into upper bits

12 Irvine, Kip R. Assembly Language For Intel-Based Computers MOVZX and MOVSX Examples.data var16 dw 1234h var8 db -2; FEh.code mov bl,22h movzx ax,bl; AX = 0022h movzx edx,var16; EDX = 00001234h movsx cx,var8; CX = FFFEh


Download ppt "Irvine, Kip R. Assembly Language For Intel-Based Computers.data string db "This is a string." COUNT = ($–string) ; calculate string length.code mov cx,COUNT."

Similar presentations


Ads by Google