
Instruction Set
4-154
MOV
MOV
Examples
This example defines and sets up the stack for a program.
This example for the SD186EM demonstration board controls the LEDs that are mapped
(using negative logic) to eight of the microcontroller’s programmable input/output (PIO) pins
according to the signal levels in AL. Because some of the LEDs on the board are mapped
to the low eight PIO pins (5–0)—and some are mapped to the next eight PIO pins (15–
14)—the example duplicates the signal levels in AH. Before writing the PIO signal levels
to the PIO Data 0 (PDATA0) register, the example uses NOT to convert them to negative
logic.
This example sets up the Data Segment (DS) register and the Extra Segment (ES) register
with the same segment address. This is useful if you will be using MOVS to copy one string
to another string stored in the same segment. If you set up DS and ES with different segment
addresses, you must copy the value in one of them to the other—or override the source
segment—before using MOVS.
; define stack segment
SEG_STACK
SEGMENT
DB
’STACK’
500 DUP ()
STACK:
SEG_STACK
ENDS
; set up stack (in code segment)
MOV
MOV
MOV
MOV
AX,SEG_STACK
SS,AX
AX,STACK
SP,AX
; load stack segment into SS
; SS points to SEG_STACK
; load stack offset into SP
; SP points to STACK
; control LEDs mapped using negative logic
; load eight LED signal levels into AL
...
; write to LEDs
MOV
MOV
NOT
OUT
DX,PIO_DATA0_ADDR
AH,AL
AX
DX,AX
; address of PDATA0 register
; copy AL to AH
; LEDs are negative logic
; write out signals to port
; set up DS and ES with same segment address
; direct assembler that both DS and ES point to
; the same segment of memory
ASSUME
DS:SEG_C, ES:SEG_C
; set up DS and ES with SEG_C segment
; (can’t copy directly from memory location
; to segment register)
MOV
AX,SEG_C
MOV
DS,AX
MOV
ES,AX
; load same segment into DS and ES
; DS points to SEG_C
; ES points to SEG_C