type and size operators
Download
Skip this Video
Download Presentation
TYPE and SIZE Operators

Loading in 2 Seconds...

play fullscreen
1 / 14

TYPE and SIZE Operators - PowerPoint PPT Presentation


  • 75 Views
  • Uploaded on

TYPE and SIZE Operators. TYPE returns the size, in bytes of a single element of a data label (variable) LENGTH returns a count of the number of individual elements in a data label that uses the DUP operator SIZE returns the product of TYPE * LENGTH. TYPE.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' TYPE and SIZE Operators' - essien


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
type and size operators
TYPE and SIZE Operators
  • TYPE
    • returns the size, in bytes of a single element of a data label (variable)
  • LENGTH
    • returns a count of the number of individual elements in a data label that uses the DUP operator
  • SIZE
    • returns the product of TYPE * LENGTH

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

slide2
TYPE

TYPE returns the size attribute:

.data

myByte db 1,2,3,4

myWord dw 1000h,2000h,3000h

myDouble dd 12345678h

myQuad dq 1,2,3

.code

mov ax,TYPE myByte ; 1

mov ax,TYPE myWord ; 2

mov ax,TYPE myDouble ; 4

mov ax,TYPE myQuad ; 8

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

length
LENGTH

Returns a count of the number of individual elements in a data label that uses the DUP operator:

.data

myByte db 20 dup(?)

myWord dw 5 dup(0)

.code

mov ax,LENGTH myByte ; 20

mov ax,LENGTH myWord ; 5

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

slide4
SIZE

Returns TYPE multiplied by LENGTH:

.data

myByte db 20 dup(?)

myWord dw 5 dup(0)

.code

mov ax,SIZE myByte ; 20 (20 * 1)

mov ax,SIZE myWord ; 10 (5 * 2)

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

jmp and loop instructions
JMP and LOOP Instructions
  • JMP is an unconditional jump to a code label
  • LOOP creates a counting loop, using CX as the default counter
    • LOOPD uses ECX as the counter register
    • LOOPW uses CX as the counter register
      • (only necessary in 32-bit mode programming)

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

jmp distance modifiers
JMP: Distance Modifiers
  • JMP SHORT destination
    • +/- 127 bytes
  • JMP NEAR PTR destination
    • same code segment
    • (default in the small and compact memory models)
  • JMP FAR PTR destination
    • different code segment
    • (default in the large, medium, and huge memory models)

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

jmp example
JMP Example

Label1:

.

.

jmp Label1

Unconditional Transfer of control to a label:

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

loop instruction
LOOP Instruction
  • Automatically uses CX as the counter
    • decrements it automatically
  • If CX > 0, LOOP transfers control to a label
    • otherwise, excecution drops through

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

loop example
LOOP Example

Task: sum the integers { 1,2,3,4,5 }

mov cx,5 ; loop counter

mov bx,1 ; value to be added

mov ax,0 ; holds the sum

L1:

add ax,bx

inc bx

Loop L1

; AX=000F, BX=0006, CX=0000

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

indirect addressing
Indirect Addressing
  • Indirect Operands

[si]. [di], [bx], [bp]

  • Based and Indexed Operands

array[si], array[di], array[bx]

  • Base-Index Operands

[bx+si], [bx+di]

  • Base-Index with Displacement

array[bx+si], array[bx+di]

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

indirect operand example
Indirect Operand Example

.data

aString db "ABCDEFG“

.code

mov bx,offset aString

add bx,5

mov dl,[bx]

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

adding 8 bit integers
Adding 8-bit Integers

.data

aList db 10h,20h,30h

sum   db 0

.code

mov bx,offset aList   

mov al,[bx] ; AL = 10h

inc bx

add al,[bx] ; AL = 30h

inc bx

add al,[bx] ; AL = 60h

mov si,offset sum ; get offset of sum

mov [si],al ; store the sum

If you want to paste a code example such as this into a program, remember that the code segment must always begin with the following statements:

mov ax,@data

mov ds,ax

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

adding 16 bit integers
Adding 16-bit Integers

.data

wordList dw 1000h,2000h,3000h, 0

.code

mov bx,offset wordList

mov ax,[bx] ; first number

add ax,[bx+2] ; second number

add ax,[bx+4] ; third number

mov [bx+6],ax ; store the sum

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

32 bit registers
32-Bit Registers

The .386 directive permits any of the following registers to be used as indirect operands: EAX, EBX, ECX, EDX, ESI, EDI, EBP

.386

mov ax,[ebx+3]

mov dl,string[edx]

mov ecx,[esi]

mov ebx,[eax]

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

ad