MOV AX, [1200H] MOV AX, [1200H] MOV AX, 0002H
ADD AX, [1202H] MOV BX, [1202H] MOV BX, 0003H
MOV [1300H], AX ADD AX, BX ADD AX, BX
HLT M OV [1300H], AX MOV [1300H], AX
HLT HLT
MOV AX, [1200H] Find 2’s complement
MOV BX, [1202H] MOV AX, [1200H]
MUL BX NOT AX
MOV [1300H], AX INC AX
MOV [1302H], DX MOV [1300H], AX
HLT HLT
INPUT: [1200H] =0002H INPUT – 1200 – FF
[1202H] =0003H OUTPUT – 1300 – 01
OUTPUT: [1300H] =0006H
[1302H] =0000H
Find the factorial of given any 8 bit number.
MOV AX,0005H
MOV CX,AX
DEC CX
LOOP : MUL CX
DEC CX
JNZ LOOP
MOV [1300H],AX
HLT
OUTPUT: [1300H] = ?????
Transfer a block of data from one memory location to another memory location.
MOV SI, 1200H
MOV DI, 1300H
MOV CX, 0005H
LOOP: MOV AL, [SI]
MOV [DI], AL
INC SI
INC DI
DEC CX
JNZ LOOP
HLT
SOURCE DESTINATION
INPUTS - 1200 – 01 OUTPUTS - 1300 – 01
1201 – 02 1301 – 02
1202 – 03 1302 – 03
1203 – 04 1303 – 04
1204 – 05 1304 - 05
STUDY OF STEPPER MOTOR
Simple program for run the stepper motor in clockwise and anti clockwise.
START: MOV DI, 1200H
MOV CL, 04H
LOOP2: MOV AL, [DI]
OUT C0, AL
MOV DX, 1010H
LOOP1: DEC DX
JNZ 100F (LOOP1)
INC DI
LOOP 1007H (LOOP2)
JMP 1000H (START)
FOR CLOCKWISE DATA: - 09 05 06 0A
FOR ANTI CLOCKWISE DATA: - 0A 06 05 09
INPUTS – 1200 – 09H
1201 – 05H
1202 – 06H
1203 – 0AH
Find out the largest number in a given data array.
mov ax,0000h ;AX=00
mov si,1200h ;1200=03
mov cx,[si] ;CX=03
loop2: add si,0002h ;1202=01 / 1204=5 / 1206=02
cmp ax,[si] ;Compare AX with content of 1202
;Compare AX with content of 1204
;Compare AX with content of 1206
jnc loop1 ;00-01 (Jump if no carry)
;01-05 (Jump if no carry)
;05-02 (Jump if no carry)
mov ax,[si] ;AX=01 / 05 / No use of this instruction
loop1: dec cx ;CX=02 / 01 / 00
jnz loop2 ;Jump if not zero go to loop (CX)
mov [1300h],ax ;Content of AX move to 1300
hlt ;End of the program
INPUT: [1200H] =0003H
[1202H] =0003H
[1204H] =0005H
[1206H] =0001H
OUTPUT: [1300H] = 0005H
Find out the smallest number in a given data array.
mov ax,3fffh
mov si,1200h
mov cx,[si]
loop2: add si,0002h
cmp ax,[si]
jc loop1
mov ax,[si]
loop1: dec cx
jnz loop2
mov [1300h],ax
hlt
INPUT: [1200H] =0003H
[1202H] =0003H
[1204H] =0005H
[1206H] =0001H
OUTPUT: [1300H] = 0001H
Ascending order
MOV DX,0004H ;DX=0004
LOOP3: MOV CX,DX ;CX=0004
MOV SI,1200H ;1200=55
LOOP2: MOV AX,[SI] ;AX=55 / 55 / 55 / 55
CMP AX,[SI+02H] ;AX with content of 1202 (1202=44)
;AX with content of 1204 (1204=44)
;AX with content of 1206 (1206=11)
;AX with content of 1208 (1208=22)
JL LOOP1 ;JUMP IF LESS (If AX is less then jump to the loop1)
XCHG [SI+02H],AX ;AX=44 1202=55
;AX=33 1204=55
;AX=11 1206=55
;AX=22 1208=55
XCHG [SI],AX ;1200=44 AX=55
;1202=33 AX=55
;1204=11 AX=55
;1206=22 AX=55
LOOP1: ADD SI,02H ;1204=33 / 1206=11 / 1208=22 / 120A=????
DEC CX ;CX=03 / 02 / 01 / 00
JNZ LOOP2 ;CX not zero then go to loop2 / repeat / repeat / come out from loop
DEC DX ;Now DX will decremented by one
JNZ LOOP3 ;DX not zero then go to loop3 / repeat / repeat / come out from loop
HLT ;End of your program
INPUT: [1200H] =0055H
[1202H] =0044H
[1204H] =0033H
[1206H] =0011H
[1208H] =0022H
1st step
55 44 33 11 22
44 55 33 11 22
44 33 55 11 22
44 33 11 55 22
44 33 11 22 55
2nd step
44 33 11 22 55
33 44 11 22 55
33 11 44 22 55
33 11 22 44 55
33 11 22 44 55
rd
3 step
33 11 22 44 55
11 33 22 44 55
11 22 33 44 55
11 22 33 44 55
11 22 33 44 55
4th step
11 22 33 44 55
11 22 33 44 55
11 22 33 44 55
11 22 33 44 55
11 22 33 44 55
Decending order
MOV DX,0004H
LOOP3: MOV CX,DX
MOV SI,1200H
LOOP2: MOV AX,[SI]
CMP AX,[SI+02H]
JNL LOOP1
XCHG [SI+02H],AX
XCHG [SI],AX
LOOP1: ADD SI,02H
DEC CX
JNZ LOOP2
;LOOP LOOP2
DEC DX
JNZ LOOP3
HLT
INPUT: [1200H] =0099H
[1202H] =0022H
[1204H] =0044H
[1206H] =0055H
[1208H] =0077H
Traffic light control system
; controlling external device with 8086 microprocessor.
; realistic test for c:\emu8086\devices\Traffic_Lights.exe
#start=Traffic_Lights.exe#
name "traffic"
start: mov cl,02h
mov ax,0249h
out 04,ax
mov si,1200h
loop1: mov ax,[si]
out 04,ax
call delay
add si,0002h
dec cl
jnz loop1
jmp start
delay: mov dx,0399h
loop2: dec dx
jnz loop2
ret
;INPUT DATA
;1200 = 030C
;1202 = 0861
Stepper Moter
; this is an example of out instruction.
; it writes values to virtual i/o port
; that controls the stepper-motor.
; c:\emu8086\devices\stepper_motor.exe is on port 7
#start=stepper_motor.exe#
name "stepper"
#make_bin#
steps_before_direction_change = 20h ; 32 (decimal)
;jmp start
start: mov di,1200h
mov cl,04h
loop2: mov al,[di]
out 7,al
mov dx,0fh
back: dec dx
jnz back
inc di
loop loop2
jmp start
; ========= data ===============
; bin data for clock-wise
; half-step rotation:
datcw db 0000_0110b
db 0000_0100b
db 0000_0011b
db 0000_0010b
; bin data for counter-clock-wise
; half-step rotation:
datccw db 0000_0011b
db 0000_0001b
db 0000_0110b
db 0000_0010b
; bin data for clock-wise
; full-step rotation:
datcw_fs db 0000_0001b
db 0000_0011b
db 0000_0110b
db 0000_0000b
; bin data for counter-clock-wise
; full-step rotation:
datccw_fs db 0000_0100b
db 0000_0110b
db 0000_0011b
db 0000_0000b
Clockwise Data: - 01 03 06 00
Anticlockwise Data: - 04 06 03 00