Saturday, 15 August 2015

Assembly system time DOS -



Assembly system time DOS -

i wrote code:

petla: mov ah,2 int 1ah mov[sekunda], dh mov ah, [sekunda] mov cl, 4 , ah, 11110000b shr ah, cl mov dl, ah add together dl, '0' mov ah, 2 int 21h mov ah, [sekunda] , ah, 00001111b mov dl, ah add together dl, '0' mov ah, 2 int 21h jmp petla sekunda db 0

when run programme shows me lot of values (seconds) looks this:

12 12 12 12 12 13 13

how modify code show 1 time 1 values ( 1 seconds 1 value)?

how can modify code show illustration time every 5 sec?

i need main code after x seconds changed.

remember seconds very long periods of time computer (well, lastly 40-50 years @ least!)

your little programme grabbing time value quickly, can current time several one thousand (million even!) times second.

if want output when changes, seek following: (we're adding comparison)

petla: mov ah,2 int 1ah ; time mov ah, [sekunda] ; retrieve lastly value cmp ah, dh ; same lastly value? jz pet1a ; yup, ignore it, loop again! mov [sekunda], dh ; save seconds mov ah, [sekunda] ; seconds value mov cl, 4 ; ready shift 4 bits , ah, 11110000b ; isolate top nybble shr ah, cl ; shift low nybble mov dl, ah ; move proper register output add together dl, '0' ; magically transform ascii digit mov ah, 2 ; select 'write char' int 21h ; uh... write char! mov ah, [sekunda] ; hey, seems familiar! , ah, 00001111b ; isolate lower nybble! mov dl, ah ; no, really.. deja vu! add together dl, '0' ; taadaa, it's char! mov ah, 2 ; select 'write char' int 21h ; create so! jmp petla ; again! (make 'ret', see below)

now little routine output new value every second... perhaps not valuable...

but wait! there's more!

if alter lastly instruction (jmp pet1a) homecoming (ret), can utilize part of 'wait_for_five_seconds' routine... so:

wait_for_five_seconds: mov al,5 ; how many seconds wait wait_for_al_seconds: ; explained below wait_loop: force ax ; save our counter (al) phone call pet1a ; phone call pet1a, not homecoming until has displayed new sec value pop ax ; retrieve our counter (pet1a changes value of ah/al/ax, remember?) dec al ; decrease al 1 (does not set flags!!) or al,al ; set flags jnz wait_loop ; al=0? nope, around go again! ret ; go whomever called us!

now, if wanted pause 5 seconds, simple phone call wait_for_five_seconds , it'll work!

if remove part of pet1a writes characters out... have silent delay of 1 second. useful pausing.

what if wanted pause 17 seconds? hmmm, our delay based on value of al when come in wait_loop section... if preloaded al, called wait bit?

mov al, 17 ; delay 17 seconds! phone call wait_for_al_seconds ; delay whatever number in al

be careful though, if al has value of 0... has loop way around... 0, -1, -2, ... -127, -128, 127, 126... 2, 1, 0 ... you'd pause 256 seconds! (4 minutes, 16 seconds!). (see signed number representations why went weird around -128)

i hope has helped , perhaps given ideas. it's not thought 'pause' solution since isn't exact delay, if called pet1a just before new sec ticked over, delay teeny-tiny first click, total seconds rest... desired delay of 5 seconds anywhere 4.000001 seconds 5 seconds long. it's start.

assembly dos 8086

No comments:

Post a Comment