Saturday, April 19, 2014

8255 interfacing with 8086 ADC

Problem Statement: 8255

Write 8086 ALP to convert an analog signal in the range of 0V to 5V to its corresponding digital signal using successive approximation ADC and dual slope ADC. Find resolution used in both the ADC's and compare the results.

0000:4000  MOV AL, 99
0000:4002  OUT 67, AL
0000:4004  MOV AL, 05
0000:4006 OUT 63, AL
0000:4007  MOV AL, 04
0000:4009  OUT 63, AL
0000:400B  IN AL, 65
0000:400D  AND AL, 01
0000:400F  JZ  400B
0000:4011  MOV AL, 02
0000:4013  OUT 63 ,AL
0000:4016  IN AL, 61
0000:4018  INT 3                                             

8255 interfacing with 8086 DAC

Problem Statement: 8255
Write 8086 ALP to interface DAC and generate following waveforms on oscilloscope,
(i) Square wave - Variable Duty Cycle and Frequency.
(ii) Ramp wave - Variable direction
(iii) Trapezoidal wave 
(iv) Stair case wave

----------------------------Square wave--------------------------

0000:4000 MOV CL,FF
0000:4002  DEC CL
0000:4004  JNZ 4002
0000:4006 RET
0000:4007  MOV AL, 80
0000:4009  OUT 67, AL
0000:400B  MOV AL, 01
0000:400D  OUT 63, AL
0000:400F  MOV AL, 00
0000:4011  OUT 61, AL
0000:4013  CALL 4000
0000:4016  MOV AL, FF
0000:4018  OUT 61, AL
0000:401A  CALL 4000
0000:401D  JMP 400F
0000:401F  INT 3     

----------------------------Staircase wave-----------------------


0000:2050  MOV AL, 80
0000:2052  OUT 67, AL
0000:2054  MOV AL, 01
0000:2056  OUT 63, AL
0000:2058  MOV AL, 00
0000:205A  OUT 61, AL
0000:205C  CALL 1000
0000:205F  MOV AL, 55
0000:2061  OUT 61, AL
0000:2063  CALL 1000
0000:2066  MOV AL, AA
0000:2068  OUT 61, AL
0000:206A  CALL 1000
0000:206D  MOV AL, FF
0000:206F  OUT 61, AL
0000:2071  CALL 1000
0000:2074  MOV AL, AA
0000:2076  OUT 61, AL
0000:2078  CALL 1000
0000:207B  MOV AL, 55
0000:207D  OUT 61, AL
0000:207F  CALL 1000
0000:2082  MOV AL, 00
0000:2084  JMP 205A
0000:2086  INT 3    

----------------------------Square tooth wave--------------------

0000:5000  MOV AL,80
0000:5002  OUT 67,AL
0000:5004  MOV AL,01
0000:5006  OUT 63,AL
0000:5008  MOV AL,00
0000:500A  OUT 61,AL
0000:500C  INC AL
0000:500E  OUT 61,AL
0000:5010  CMP AL,FF
0000:5012  JNZ 500C
0000:5014  JMP 5008
0000:5016  INT 3                  
  
----------------------------Saw tooth wave----------------------

0000:6000  MOV AL,80
0000:6002  OUT 67,AL
0000:6004  MOV AL,01
0000:6006  OUT 63,AL
0000:6008  MOV AL,FF
0000:600A  OUT 61,AL
0000:600C  DEC AL
0000:600E  OUT 61,AL
0000:6010  CMP AL,00
0000:6012  JNZ 600C
0000:6014  JMP 6008
0000:6016  INT 3  
  
----------------------------Triangular wave----------------------


0000:7000  MOV AL, 80
0000:7002  OUT 67, AL
0000:7004  MOV AL, 01
0000:7006  OUT 63, AL
0000:7008  MOV AL, 00
0000:700A  OUT 61, AL
0000:700C  INC AL
0000:700E  OUT 61, AL
0000:7010  CMP AL, FF                                            
0000:7012  JNZ 700C
0000:7014  DEC AL
0000:7016  OUT 61, AL
0000:7018  CMP AL, 00
0000:701A  JNZ 7014
0000:701C  JMP 7008
0000:701E  INT 3                                                 

Math co-processor 8087 program to obtain Mean, Variance and Standard Deviation in NASM[x86/64]


Problem Statement: Write 8087 ALP to obtain:
i) Mean ii) Variance iii) Standard Deviation
For a given set of data elements defined in data segment. Also display result.




section .data

numbers db "The numbers are:102.59,198.21,100.67,230.78,67.93",10
len equ $-numbers
meanmsg db 10,"CALCULATED MEAN IS:-"
meanmsg_len equ $-meanmsg
sdmsg db 10,"CALCULATED STANDARD DEVIATION IS:-"
sdmsg_len equ $-sdmsg
varmsg db 10,"CALCULATED VARIANCE IS:-"
varmsg_len equ $-varmsg
array dd 102.56,198.21,100.67,230.78,67.93
arraycnt dw 05
dpoint db '.'
hdec dq 100

section .bss
dispbuff resb 1
resbuff rest 1

mean resd 1
variance resd 1

%macro linuxsyscall 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro   


section .text
global _start
_start:
linuxsyscall 01,01,numbers,len
finit
fldz
mov rbx,array
mov rsi,00
xor rcx,rcx
mov cx,[arraycnt]

up:
fadd dword[RBX+RSI*4]
inc rsi
loop up

fidiv word[arraycnt]
fst dword[mean]
linuxsyscall 01,01,meanmsg,meanmsg_len
call dispres

mov rcx,00
mov cx,[arraycnt]
mov rbx,array
mov rsi,00
FLDZ

up1:
FLDZ
FLD dword[RBX+RSI*4]
FSUB dword[mean]
FST ST1
FMUL
FADD
inc rsi
loop up1

FIDIV word[arraycnt]
FST dword[variance]
FSQRT
linuxsyscall 01,01,sdmsg,sdmsg_len
CALL dispres

FLD dword[variance]
linuxsyscall 01,01,varmsg,varmsg_len
CALL dispres

exit: 
mov rax,60
mov rdi,0
syscall


disp8_proc:
mov rdi,dispbuff
mov rcx,02

back:
rol bl,04
mov dl,bl
and dl,0FH
cmp dl,09
jbe next1
add dl,07H

next1:  
add dl,30H
mov [rdi],dl
inc rdi
loop back
ret

dispres:
fimul dword[hdec]
fbstp tword[resbuff]
xor rcx,rcx
mov rcx,09H
mov rsi,resbuff+9

up2:
push rcx
push rsi
mov bl,[rsi]
call disp8_proc

linuxsyscall 01,01,dispbuff,2
pop rsi
dec rsi
pop rcx
loop up2

linuxsyscall 01,01,dpoint,1
mov bl,[resbuff]
call disp8_proc
linuxsyscall 01,01,dispbuff,2
ret

Output

amodi@ubuntu:~/MIL/Assign7$ nasm -f elf64 -l asgn7.lst asgn7.asm
amodi@ubuntu:~/MIL/Assign7$ ld -o asgn7 asgn7.o
amodi@ubuntu:~/MIL/Assign7$ ./asgn7
The numbers are: 102.59,198.21,100.67,230.78,67.93

CALCULATED MEAN IS:-000000000000000140.30
CALCULATED STANDARD DEVIATION IS:-000000000000000062.32
CALCULATED VARIANCE IS:-000000000000003954.34
 

Multiplication of 2 8-bit Hexadecimal numbers using Successive addition & booth's algorithm in NASM[x86/64 architecture]

Problem Statement: Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. Use successive addition and add and shift method. Accept input from the user. (use of 64-bit registers is expected).
 
%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

SECTION .data
msg1: db "Enter number: "
len1: equ $-msg1
msg2: db "Result: "
len2: equ $-msg2
msg3: db "",10
len3: equ $-msg3
msg4: db "1. Booths algorithim",10,"2. Successive addition",10
len4: equ $-msg4


SECTION .bss
result: resb 4
count1: resb 2
count2: resb 2
num: resb 3
temp: resb 1
choice: resb 2

SECTION .text
global  main
main:
menu:
print msg4,len4
accept choice,2
cmp byte[choice],31h
je ch1
cmp byte[choice],32h
je ch2

ch1:
mov byte[count2],10h
print msg1,len1
accept num,3
call asc_hex
mov r9,rbx

print msg1,len1
accept num,3
call asc_hex
mov r10,rbx

mov cx,00h
mov rcx,r9
bt cx,0
jc q1
jnc q2

q1:
mov rax,r10
shl rax,16
sub ecx,eax
jmp q2

q3:
mov rax,r10
shl rax,16
add ecx,eax
jmp q2

q2:
bt cx,0h
jc carryset
jnc carrynotset
back:
sar ecx,01h
dec byte[count2]
jnz mul
jz x

carryset:
mov al,01h
mov byte[temp],al
jmp back

carrynotset:
mov al,00h
mov byte[temp],al
jmp back

mul:
mov al,byte[temp]
cmp al,0h
jz x1
jnz x2

x1:
bt cx,0
jc q1
jnc q2

x2:
bt cx,0
jc q2
jnc q3

x:
xor rbx,rbx
mov rbx,rcx
call hex_asc
print msg2,len2
print result,16
print msg3,len3
jmp exit

ch2:
print msg1,len1
accept num,3
call asc_hex
mov r9,rbx

print msg1,len1
accept num,3
call asc_hex
mov cx,bx
xor rax,rax

add1:
add rax,r9
dec cl
jnz add1
mov rbx,rax
call hex_asc
print msg2,len2
print result,16
print msg3,len3

jmp exit


exit:
mov rax,60
mov rdi,1
syscall


asc_hex:
mov rbx,00
mov r11,0
mov ch,02
loop:
mov al,[num+r11]
cmp al,61h
jb next
sub al,57h
jmp next2
next:
cmp al,41h
jb next1
sub al,37h
jmp next2
next1:
sub al,30h
next2:
shl rbx,04h
add rbx,rax
inc r11
dec ch
jnz loop
ret

hex_asc:
mov byte[count1],16h
mov r11,rbx
mov r12,result
l1:
rol rbx,04h
mov dl,bl
and dl,0Fh
cmp dl,09h
jbe l2
add dl,07h
l2:
add dl,30h
mov [r12],dl
inc r12
dec byte[count1]
jnz l1
ret

Output

amodi@ubuntu:~/MIL/Assign6$ nasm -f elf64 -l asgn6.lst asgn6.asm
amodi@ubuntu:~/MIL/Assign6$ ld -o asgn6 asgn6.o
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
amodi@ubuntu:~/MIL/Assign6$ ./asgn6
1. Booths algorithim
2. Successive addition
1
Enter number: 02
Enter number: 05
Result: 00000000000000A
amodi@ubuntu:~/MIL/Assign6$ ./asgn6
1. Booths algorithim
2. Successive addition
2
Enter number: 02
Enter number: 03
Result: 000000000000006


String manipulation operations (concatenation, substring) using FAR procedure call in NASM[x86/64 architecture]

Problem Statement: Write 8086 ALP to perform string manipulation. The strings to be accepted from the user is to be stored in data segment of program_l and write FAR PROCEDURES in code segment program_2 for following operations on the string:
(a) Concatenation of two strings (b) Number of occurrences of a sub-string in the given string Use PUBLIC and EXTERN directive. Create .OBJ files of both the modules and link them to create an EXE file.


-----------------------------------------------------------------

asgn5.asm file:

global str1,str2,msg2,msg3,len2,len3
extern concate1,substr1

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro accept 2
mov rax, 0
mov rdi, 0
mov rsi, %1
mov rdx, %2
syscall
%endmacro

SECTION .data
msg1: db "Enter choice",10,"1. Concatenate",10,"2. Number of substrings",10,"3. Exit",10,"Enter your choice: "
len1: equ $-msg1
msg2: db "Enter the first string: "
len2: equ $-msg2
msg3: db "Enter the second string: "
len3: equ $-msg3

SECTION .bss
str1: resb 50
str2: resb 50
choice: resb 2

SECTION .text
global main:
main:
menu:
print msg1,len1
accept choice,2
cmp byte[choice],31h
je ch1
cmp byte[choice],32h
je ch2
cmp byte[choice],33h
je ch3

ch1:
call concate1
jmp menu

ch2:
call substr1
jmp menu

ch3:
mov rax,60
mov rdi,1

syscall

-----------------------------------------------------------------

asgn5_1.asm file:

extern str1,str2,msg2,msg3,len2,len3
global concate1,substr1

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro accept 2
mov rax, 0
mov rdi, 0
mov rsi, %1
mov rdx, %2
syscall
%endmacro

SECTION .data
msg4: db 10,"The number of substrings are: "
len4: equ $-msg4
msg5: db 10,"The concatenated string is: "
len5: equ $-msg5
msg6: db "",10
len6: equ $-msg6

SECTION .bss
ln1: resb 2
ln2: resb 2
ln21: resb 2
str3: resb 50
count: resb 2

SECTION .text
concate1:
mov byte[str1],0h
mov byte[str2],0h

print msg2,len2
accept str1,50
mov byte[ln1],al
sub byte[ln1],1

print msg3,len3
accept str2,50
mov byte[ln2],al
sub byte[ln2],1

mov r9,str1
mov r10,str3

loop1:
mov bl,[r9]
mov [r10],bl
inc r9
inc r10
dec byte[ln1]
jnz loop1
mov r9,str2
loop2:
mov bl,[r9]
mov [r10],bl
inc r9
inc r10
dec byte[ln2]
jnz loop2

print msg5,len5
print str3,50
print msg6,len6
ret

substr1:
mov byte[str1],0h
mov byte[str2],0h

print msg2,len2
accept str1,50
mov byte[ln1],al
sub byte[ln1],1

print msg3,len3
accept str2,50
mov byte[ln2],al
sub byte[ln2],1
mov byte[ln21],al
sub byte[ln21],1

mov r9,str1
mov r10,str2

loop:
mov al,[r9]
cmp al,[r10]
je l1
inc r9
dec byte[ln1]
cmp byte[ln1],00H
je l3
jne loop

l1:
inc r9
inc r10
dec byte[ln1]
dec byte[ln2]
jz l2
jmp loop

l2:
inc byte[count]
mov al,byte[ln21]
mov byte[ln2],al
mov r10,str2
cmp byte[ln1],00H
jne loop


l3:
xor al,al
mov al,[count]
add al,30h
mov [count],al
print msg4,len4
print count,2
print msg6,len6
ret

-----------------------------------------------------------------

Output

amodi@ubuntu:~/MIL/Assign5$ nasm -f elf64 -l asgn5.lst asgn5.asm
amodi@ubuntu:~/MIL/Assign5$ nasm -f elf64 -l asgn5_1.lst asgn5_1.asm
amodi@ubuntu:~/MIL/Assign5$ ld -o asgn5 asgn5.o asgn5_1.o
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
amodi@ubuntu:~/MIL/Assign5$ ./asgn5
Enter choice
1. Concatenate
2. Number of substrings
3. Exit
Enter your choice: 1
Enter the first string: Iron
Enter the second string: Man

The concatenated string is: IronMan
Enter choice
1. Concatenate
2. Number of substrings
3. Exit
Enter your choice: 2
Enter the first string: Iron
Enter the second string: Man

The number of substrings are: 0
Enter choice
1. Concatenate
2. Number of substrings
3. Exit
Enter your choice: 2
Enter the first string: wheat
Enter the second string: at

The number of substrings are: 1
Enter choice
1. Concatenate
2. Number of substrings
3. Exit
Enter your choice: 3 

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...