
Instruction Set
4-143
LODS
LODS
Examples
This example copies a string of 16-bit integers in one segment to a string in another
segment. The microcontroller copies the words and changes their sign—one by one, from
first to last—before storing them in the other string. Before setting up the registers for the
string operation, this example exchanges DS for ES in order to address the destination
string using ES.
; defined in SEG_S segment
SOURCE
DW
16 DUP (?)
; defined in SEG_D segment
DESTINATION
DW
LENGTH SOURCE DUP (?)
; notify assembler: DS and ES specify different segments
ASSUME DS:SEG_D, ES:SEG_S
; set up segment registers with different segments
MOV
AX,SEG_D
; load one segment into DS
MOV
DS,AX
; DS points to SEG_D, destination
MOV
AX,SEG_S
; load another segment into ES
MOV
ES,AX
; ES points to SEG_S, source
; initialize and use source string
...
; exchange DS for ES: the microcontroller does not allow
; you to override the segment register it uses to address
; the destination string (ES)
PUSH
ES
; ES points to SEG_S, source
PUSH
DS
; DS points to SEG_D, destination
POP
ES
; ES points to SEG_D, destination
POP
DS
; DS points to SEG_S, source
; set up registers and flags
LEA
SI,SOURCE
; load source offset (segment = DS)
LEA
DI,DESTINATION
; load dest. offset (segment = ES)
MOV
CX,LENGTH SOURCE
; set up counter
; LENGTH is an assembler directive
CLD
; process string low to high
LOAD:
; load integers, change their sign, and store them
LODSW
; copy integer from source to AX
NEG
AX
; change sign of integer in AX
STOSW
; copy integer from AX to dest.
LOOP
LOAD
; while CX is not zero,
; jump to top of loop
; exchange DS for ES
PUSH
ES
; ES points to SEG_D, destination
PUSH
DS
; DS points to SEG_S, source
POP
ES
; ES points to SEG_S, source
POP
DS
; DS points to SEG_D, destination
Содержание Am186 Series
Страница 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Страница 10: ...Table of Contents x...
Страница 18: ...Programming 1 8...
Страница 40: ...Instruction Set Listing 3 14...