Title: T1_P4'f98 Syntax Errors
1T1_P4.f98 Syntax Errors
ERROR messages will be removed if you leave
these first two lines in _at__at__at__at_ This program
checks N 16-bit words of array "data" and counts
how many are equal to -3. The total is stored
in variable "total". N is entered by the user,
and must be less than or equal 20. jmp gt
l1 data2 dw -3,-1,-4,-3,-2,-3,-5,-6,-3,0,-4,-3,1,
2,3,-3,-3,-3,-6,0 total db ? get_n db "How many
data points do you want to check (lt 20)? '
ERROR 32 Bad String
_at__at__at__at_ l1
ERROR 01 Unknown Mnemonic
_at__at__at__at_ call
count3 call godos
2Syntax Errors -2
count3 push ax,bx,cx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jl l2 if the number's too small cmp bx,
20h jg l2 if the number's too big
There are no syntax errors here
3T1_P4.f98 Step 1
mov cx,bl loop for n trials ERROR
13 Byte/Word Combination Not Allowed
_at__at__at__at_ mov si,0 index mov
ax,-3 -3 is the "target" check_data sub
ax,data si ERROR 39 Bad
Index Register
_at__at__at__at_ jne noteq inc cx cx counts
the number of data points -3 noteq inc
si point to the next data loop check_data
and repeat until N iterations mov total, cx
and store the result ERROR 13
Byte/Word Combination Not Allowed
_at__at__at__at_ pop ax, bx, cx, si restore
registers ret
4Result Assembles without errors
This program checks N 16-bit words of array
"data" and counts how many are equal to -3.
The total is stored in variable "total". N is
entered by the user, and must be less than or
equal 20. jmp gt l1 data2 dw -3,-1,-4,-3,-2,-3,-5,
-6,-3,0,-4,-3,1,2,3,-3,-3,-3,-6,0 total db
? get_n db 'How many data points do you want to
check (lt 20)? ' l1 call count3 call
godos co
unt3 push ax,bx,cx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jl l2 if the number's too small cmp bx,
20h jg l2 if the number's too big
Now, the hard part-- locating logic errors
5Logic Error 1
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target" check_data
sub ax,data2 si jne noteq inc cx cx
counts the number of data points -3
noteq inc si point to the next data loop
check_data and repeat until N iterations mov
total, cl and store the result pop ax, bx, cx,
si restore registers ret
Cannot redefine CX inside a loop. It is used as
the loop counter.
6Correct Logic Error 1
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target mov bl,
0 initialize counter check_data sub
ax,data2 si jne noteq inc bl cx counts
the number of data points -3 noteq inc
si point to the next data loop check_data
and repeat until N iterations mov total, bl
and store the result pop ax, bx, cx, si restore
registers ret
7Logic Error 2
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target mov bl,
0 initialize counter check_data sub
ax,data2 si jne noteq inc bl cx counts
the number of data points -3 noteq inc
si point to the next data loop check_data
and repeat until N iterations mov total, bl
and store the result pop ax, bx, cx, si restore
registers ret
8Correct Logic Error 2
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target mov bl,
0 initialize counter check_data sub
ax,data2 si jne noteq inc bl cx counts
the number of data points -3 noteq inc
si inc si point to the next data loop
check_data and repeat until N iterations mov
total, bl and store the result pop ax, bx, cx,
si restore registers ret
9Logic Error 3
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target mov bl,
0 initialize counter check_data sub
ax,data2 si jne noteq inc bl cx counts
the number of data points -3 noteq inc
si inc si point to the next data loop
check_data and repeat until N iterations mov
total, bl and store the result pop ax, bx, cx,
si restore registers ret
10 Correct Logic Error 3
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target mov bl,
0 initialize counter check_data cmp
ax,data2 si jne noteq inc bl cx counts
the number of data points -3 noteq inc
si inc si point to the next data loop
check_data and repeat until N iterations mov
total, bl and store the result pop ax, bx, cx,
si restore registers ret
CMP preserves AX
11Logic Error 4
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target mov bl,
0 initialize counter check_data cmp
ax,data2 si jne noteq inc bl cx counts
the number of data points -3 noteq inc
si inc si point to the next data loop
check_data and repeat until N iterations mov
total, bl and store the result pop ax, bx, cx,
si restore registers ret
12Correct Logic Error 4
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target mov bl,
0 initialize counter check_data cmp
ax,data2 si jne noteq inc bl cx counts
the number of data points -3 noteq inc
si inc si point to the next data loop
check_data and repeat until N iterations mov
total, bl and store the result pop si,cx, bx,
ax restore registers ret
13Logic Error 5
count3 push ax,bx,cx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jl l2 if the number's too small cmp bx,
20h jg l2 if the number's too big
14Correct Logic Error 5
count3 push ax,bx,cx,dx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list mov total, bl and store the
result pop si,dx, cx, bx, ax restore
registers ret
15Logic Error 6
count3 push ax,bx,cx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jl l2 if the number's too small cmp bx,
20h jg l2 if the number's too big
There are at most 20 elements of data1. 20h is 32
elements
16 Correct Logic Error 6
count3 push ax,bx,cx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jl l2 if the number's too small cmp bx,
20 jg l2 if the number's too big
17Logic Error 7
count3 push ax,bx,cx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jl l2 if the number's too small cmp bx,
20 jg l2 if the number's too big
18Correct Logic Error 7
count3 push ax,bx,cx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jb l2 if the number's too small cmp bx,
20 ja l2 if the number's too big
19An Observation
count3 push ax,bx,cx,si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jb l2 if the number's too small cmp bx,
20 ja l2 if the number's too big
These two statements are unnecessary. No number
is below 0
20Corrected Program
count3 push ax,bx,cx,dx, si store registers so
they're not changed l2 call cls lea dx,
get_n call list call decibin BX gets N cmp
bx, 0 jb l2 if the number's too small cmp bx,
20h ja l2 if the number's too big
21Corrected Program
mov cx,bx loop for n trials mov si,0
index mov ax,-3 -3 is the "target mov bl,
0 initialize counter check_data sub
ax,data2 si jne noteq inc bl cx counts
the number of data points -3 noteq inc
si inc si point to the next data (words) loop
check_data and repeat until N iterations mov
total, bl and store the result pop
si,dx,cx,bx,ax restore registers ret
22Problem 3
jmp gt l1 data1 db 0,1,2,3,4,5,10,9,8,7,6,5,11,12,1
3,14,15,20,19,18,17,16,15 mean db ? remn db
? l1 call get_mean call godos
23get_mean jmp gt l1 how_many db 'How many numbers
do you want to average? ' cont db 'Press any key
to continue ' l1 push ax,bx,cx,dx, si call
cls lea dx, how_many call list call decibin
bx gets number cmp bx, 25 ja l1 too big mov
cx, bx to set up loop mov si,0 initialize
index mov ax,0 initialize summer loop_total
add al,data1si al al data1si inc
si point to next number loop loop_total div
bl total/N mov remn,ah mov mean,al
24lea dx,cont call list call keywt pop
si,dx,cx,bx,ax ret
25D/A conversion
- Input to a D/A converter
- a digital number (byte-wide in 485/486)
- Output of a D/A converter
- An analog voltageVout resolution
- In 485/486 there are 8 channels, DAC0 - DAC7
- Resolution is 18 mV/bit
- Range is 0 - 25518mV 0 4.59 V
26Port or I/O Address Space
- The A/D converter chip is not a memory chip. It
does not reside in the memory address space
accessed by the 20 address lines - The 8088 has an I/O address space addressed by
the least significant 16 address lines (64K
addresses) - IN and OUT instructions read from and write to
I/O addresses - READ WRITEMov DX, ioaddress Mov DX,
ioaddressIN al, dx OUT dx,al - DX and AL are the only registers that can be used
27IN, OUT options
- An immediate 8-bit address can be used instead of
the DX register - IN al, 0feh OUT 73h,al
- The AX register can be used instead of AL.
- IN AX, DX AL?DX in I/O space AH?DX1
in I/O space - OUT DX, AX DX in I/O space ? AL
DX1 in I/O space ? AH
28IO.EQU
DAC0 0238h DAC 0 AD 7228 Port 0
gt DAC1 0239h DAC 1 AD 7228 Port
1 gt DAC2 023Ah DAC 2 AD 7228
Port 2 gt DAC3 023Bh DAC 3 AD
7228 Port 3 gt 0 to 5 Volts Output DAC4
023Ch DAC 4 AD 7228 Port 4 gt
DAC5 023Dh DAC 5 AD 7228 Port 5
gt DAC6 023Eh DAC 6 AD 7228 Port
6 gt DAC7 023Fh DAC 7 AD 7228
Port 7 gt
29An example
- Mov DX, DAC0 puts the I/O address of DAC0 in DX
- Mov Al, 5
- OUT DX, al 90 mV appears at the output of DAC0
- WARNING! The voltages remain on the D/A outputs
until the computer is reset. As part of good
housekeeping, please set all D/A outputs to zero
before returning to DOS.