Re: lab help
- From: "Jean-François Michaud" <spamtrap@xxxxxxxxxx>
- Date: 4 Oct 2006 14:31:27 -0700
Matthias wrote:
hey guys and gals,
i have been browsing around for a while. and i got stuck on this one
lab question. 'count from 0-50BCD, display the equivalent numbers in
hex on the monitor, and output the values in decimal to a 7-segment
display (using the parallel port)'. I was working on it on the
weekend, i got this far.
.model tiny
.486
.stack
.data
.code
.startup
mov ax, 0; clears the register
To clear the register, it is best to use XOR instead of mov. Much
faster than a mov instruction:
xor ax, ax
next: NOP
NOP is probably useless here, you can drop it.
inc al;starts the count
mov bx, 2000
mov [bx], al
mov [bx+1], ah
call displaymon; at 150, for personal reference
call output; at 160, for personal reference
call delay; at 170, for personal reference
cmp al, 0AH; compares to 10
jnz next; does the loop again, if less than 10
jz add2reg2; adds one to another register, and resets this one back to
0
cmp ah, 5; compares reg2 to 5
jnz next
;jz clear; this part is commented out so that i can see if the rest
was working
add2reg2: add ah, 1
mov al, 0
jmp next
;clear: mov ax, 0; this part is commented out so that i can see if the
rest was working
; jmp next; this part is commented out so that i can see if the rest
was working
.exit
' a friend of mine said that the procedure displaymon, can be done a
lot, simpler. what mine right now does is... well i am not quite sure
anymore.
If you're not sure, you should start from scratch with what you
understand :). I know it's tough to let go but starting afresh will
help you alot.
but i was told there is an easier way to convert numbers to
hex (from the standard main count of bcd) and display them.
BCD numbers are already coded in hex. A basic way to resolve your
project would be to keep 2 counts instead of 1 with a convertion from a
HEX count to BCD. The 2 counts idea involves keeping a HEX count like
you are doing and a BCD count. You basically wouldnt need to worry
about anything when displaying neither of them since you would have
your hex count kept in sync with your BCD count. You just output each
BCD or HEX nibbles directly. The problem with BCD is counting.
The idea is if you reach 9 on your low nibble and you're about to
increment, you reset your lowest nibble to 0 and you increment the high
nibble by 1.
When counting, your nibbles can't go over 9.
The logic goes like this for BCD:
0h, 1h, 2h, 3h, 4h, 5h, 6h, 7h, 8h, 9h, 10h, 11h, etc.
You count as you would normally in decimal notation. The hick is that
if you increment a count on an hexadecimal number, you'll bust the
number 9 limit which would result in this
0h, 1h, 2h, 3h, 4h, 5h, 6h, 7h, 8h, 9h, Ah, Bh, etc.
Just concentrate on implementing both counts and your lab will be a
breeze :).
I strongly suggest you start from scratch to build a solid
understanding based on the new idea of using 2 counts that you keep in
sync, one in BCD and the other in HEX. Does your work statement say
anywhere that you have to convert your hex count to BCD? If it doesn't,
the double count idea will be more straighforward to implement than the
conversion from hex to BCD (It will probably be faster too at the
expense of using 8 more bits to store the second count).
[SNIP]
Regards
Jean-Francois Michaud
.
- References:
- lab help
- From: Matthias
- lab help
- Prev by Date: Re: about assembly compiler
- Next by Date: Re: about assembly compiler
- Previous by thread: lab help
- Next by thread: Having trouble posting?
- Index(es):
Relevant Pages
|