Вы находитесь на странице: 1из 2

##################################################

#########################

Program for implementing gates

##################################################
#########################

.aseg value,bit
.org 20h
val .dst 1
bit1 .dst 1
bit2 .dst 1
.rseg kish,code
mov psw,#80h
mov bit1,c ;Moving 1 into bit1
mov bit2,c ;Moving 1 into bit2
cjne a,#01h,next1 ;If and bit is set
call and
jmp end1
next1:
cjne a,#02h,next2 ;if nand bit is set
call nand
jmp end1
next2:
cjne a,#04h,next3 ;if xor bit is set
call xor
jmp end1
next3:
cjne a,#08h,next4 ;if not bit is set
call not
jmp end1
next4:
cjne a,#10h,next5 ;if SR Flipflop bit is set
call srf
jmp end1
next5:
;invalid option ;Invalid
jmp end1
and:
jnb bit1,lab1 ;check bit1
jnb bit2,lab1 ;check bit2
mov psw,#80h ;both bits 1
mov val,c ;moving 1 into val
jmp lab2
lab1:
mov psw,#00h ;moving 0 into val
mov val,c
lab2:
ret
nand:
call and ;calling and
cpl val ;complementing val
ret
xor:
jb bit1,yess ;if bit1 is set
jb bit2,wow ;if bit2 is set
mov psw,#80h
mov val,c ;moving 1 into val
jmp ends
yess:
jb bit2,wow
mov psw,#80h
mov val,c ;moving 1 into val
jmp ends
wow:
mov psw,#00h ;moving 0 into val
mov val,c
ends:
ret
not:
cpl val ;complement val
ret
srf:
jnb acc.4,end1 ;check if A.4 is set
jb bit1,test ;Bit1 is set
jb bit2,ok ;Bit2 is set
jmp srf
ok:
mov psw,#80h
mov val,c ;moving 1 into val
jmp srf
test:
jb bit2,end1
mov psw,#00h
mov val,c ;moving 0 into val
jmp srf
ret
end1:
nop
nop
.end

Вам также может понравиться