
Instruction Set
4-164
NEG
NEG
Examples
This example uses addition to find the difference between two integers.
This example copies a string of 8-bit integers stored in memory to another string located
in the same segment. The microcontroller copies the bytes and changes their sign—one
by one, from first to last—before storing them in the other string.
Related Instructions
If you want to
See
Toggle all bits of a component
NOT
Subtract a number and the value of CF from another number
SBB
Subtract a number from another number
SUB
INTEGER1
DW
2000
; 7D0h
INTEGER2
DW
1600
; 640h
; calculate difference using sign change and addition
NEG
INTEGER2
; INTEGER2 = F9C0h = -1600
; signed addition: INTEGER1 = IN INTEGER2
ADD
INTEGER1,INTEGER2
; INTEGER1 = 0190h = 400
; defined in SEG_C segment
SOURCE
DB
20 DUP (?)
DESTINATION
DB
LENGTH SOURCE DUP (?)
; notify assembler: DS and ES point to the
; same segment of memory
ASSUME
DS:SEG_C, ES:SEG_C
; set up DS and ES with same segment address
MOV
AX,SEG_C
; load segment into DS and ES
MOV
DS,AX
; DS points to SEG_C
MOV
ES,AX
; ES points to SEG_C
; initialize and use source string
...
; save ES
PUSH
ES
; 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
CLD
; process string low to high
LOAD:
LODSB
; copy integer to AL
NEG
AL
; change sign of integer in AL
STOSB
; copy AL to destination string
LOOP
LOAD
; while CX is not zero,
; jump to top of loop
; restore ES
POP
ES
Summary of Contents for Am186 Series
Page 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Page 10: ...Table of Contents x...
Page 18: ...Programming 1 8...
Page 40: ...Instruction Set Listing 3 14...