OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 1:51 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Which assembler?
PostPosted: Sun Apr 13, 2008 8:40 am 
Offline
Member
Member

Joined: Wed Apr 02, 2008 8:36 am
Posts: 27
Which assembler can assemble this code?

Nasm or Masm or ....what?

; stopwatch
DOSSEG
.MODEL SMALL
.STACK 4096
.DATA
Instructions db 'STOPWATCH',13,10
db '---------',13,10
db ' (S)tart S(t)op (Q)uit',13,10
db 13,10,' $'
Blank db ' $'
StartRow db ? ; position on screen of timer
StartCol db ? ; position on screen of timer
Running db 0 ; is timer running ?
TimerStart dd ? ; start value of timer

TempStr db 1,2 ; temporary storage for STDIN input
t2 db 80 dup (0)
t3 db 13,10,'$'

.CODE

ProgramStart:
mov ax,SEG _DATA ; set up data segment
mov ds,ax

lea dx,Instructions ; output instructions
mov ah,9
int 21h

mov ah,3 ; get current position on screen
xor bh,bh
int 10h
mov StartRow,dh
mov StartCol,dl

startkeys: ; loop to get/process keystrokes
mov ah,1 ; check keyboard status
int 16h

jz updateloop ; update if no keys available

mov ah,0 ; get keystroke
int 16h

cmp al,'q' ; check for QUIT key
je theend

cmp al,'s' ; check for START key
jne checkstop ; jump to next check
call start
jmp updateloop ; update display

checkstop:
cmp al,'t' ; check for STOP key
jne startkeys ; continue loop
call stop

updateloop:
cmp Running,0
je startkeys ; continue loop if timer not running

call update ; update screen

jmp startkeys ; continue loop

theend:
lea dx,t3 ; move cursor to next line
mov ah,9
int 21h

mov ah,4ch ; terminate program
int 21h

update PROC ; procedure to update timer display
mov ax,0040h ; set ES to point to BIOS data area
mov es,ax
mov ax,es:[006Ch] ; get system clock value
mov dx,es:[006Eh]
sub ax,word ptr TimerStart ; get time difference
sbb dx,word ptr TimerStart+2

mov bx,65535
div bx ; get hours in AX
mov cx,ax ; save hours value in CX
xor ax,ax
xchg ax,dx ; swap remainder into AX
mov bx,1092
div bx ; get minutes in dx
mov si,ax ; save minutes value in SI
xor ax,ax
xchg ax,dx ; swap remainder into AX
mov bx,18
div bx ; get seconds in ax
push ax ; save seconds
push si ; save minutes
push cx ; save hours

xor bh,bh ; put cursor at old position
mov dh,StartRow
mov dl,StartCol
mov ah,2
int 10h

pop ax ; restore hours
call writesint ; output hours
mov dl,':' ; output colon
mov ah,2
int 21h

pop ax ; restore minutes
call writesint ; output minutes
mov dl,':' ; output colon
mov ah,2
int 21h

pop ax ; restore seconds
call writesint ; output seconds

lea dx,Blank ; erase any digits left from old time
mov ah,9
int 21h

ret
update ENDP

start PROC ; procedure to start timer
mov ax,0040h ; set ES to point to BIOS data area
mov es,ax
mov ax,es:[006Ch] ; get system clock value
mov dx,es:[006Eh]
mov word ptr TimerStart,ax ; store clock value in TimerStart
mov word ptr TimerStart+2,dx
mov Running,1 ; set timer flag
ret
start ENDP

stop PROC ; procedure to stop timer
mov Running,0 ; clear timer flag
ret
stop ENDP

writesint PROC ; outputs the integer in the AX register

push ax ; save all registers used
push bx
push cx
push dx
push si

mov bx,10 ; radix = decimal = 10
xor si,si ; initialize digit counter
startdiv:
xor dx,dx
div bx ; divide no by 10
push dx ; save remainder
inc si ; increment digit counter
cmp ax,0 ; check for end of divisions
jne startdiv

mov cx,si ; set digit counter
mov bx,0 ; initialize position counter
makeletters:
pop ax ; get digit
add al,48 ; make integer --> ascii value
mov [t2+bx],al ; insert digit into string
inc bx ; increment position counter
loop makeletters
mov [t2+bx],'$' ; put end-of-string marker

mov ah,09h ; output integer as string
lea dx,t2
int 21h

pop si ; restore registers
pop dx
pop cx
pop bx
pop ax

ret ; return to point of call

writesint ENDP

END ProgramStart


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 8:52 am 
Offline
Member
Member

Joined: Sun Mar 23, 2008 2:23 pm
Posts: 89
Location: [0x8:0x1000]
MASM or any other assembler with a macro for MASM syntax support ;)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 8:57 am 
Offline
Member
Member

Joined: Wed Apr 02, 2008 8:36 am
Posts: 27
I have test it in Masm and nasm.but they say that the code has error.but you know i have gotten this code from Wiki and i think it has no error.

if it is possible first you assemble it first and if would work correctly please upload for me.

Thnx in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 9:15 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
steward wrote:
I have test it in Masm and nasm.but they say that the code has error.but you know i have gotten this code from Wiki and i think it has no error.

if it is possible first you assemble it first and if would work correctly please upload for me.

Thnx in advance


There are about a thousand and one posting errors in this thread, and instead of my usual painstaking ritual of working through them all, I'll just let the moderators tell you what's wrong.

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 9:36 am 
Offline
Member
Member
User avatar

Joined: Thu Feb 14, 2008 3:56 pm
Posts: 25
I'm going for a wild guess.... TASM?
Its 16-bit DOS code, and the only 16-bit assembler on DOS I've ever used was Turbo Assember, so I'm going with TASM. Could be MASM, so please tell me if I'm wrong (I've never used MASM).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 10:52 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
steward wrote:
I have test it in Masm and nasm.but they say that the code has error.but you know i have gotten this code from Wiki and i think it has no error.


I recommend to learn assembly language first before trying to use random code from the internet. Please take no offense, but it sounds like you do not have much experience with it.

In any case, please post the errors that you have gotten. iirc, MASM and TASM share alot of syntax, so it might work with both of them..

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 11:16 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
DOSSEG

Any reason for using that obsolete OS?

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 12:48 pm 
Offline
Member
Member

Joined: Wed Apr 02, 2008 8:36 am
Posts: 27
Tasm was True


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 12:42 am 
Offline
Member
Member
User avatar

Joined: Fri Jun 22, 2007 12:47 pm
Posts: 1598
Location: New Hampshire, USA
Quote:
you know i have gotten this code from Wiki and i think it has no error.


well, if it's from a wiki then it must be good code then. :roll:

why did you post this? just curious about the assembler that assembled this code? or is it something that you needed to understand?

_________________
Website: https://Joscor.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 8:15 am 
Offline
Member
Member
User avatar

Joined: Thu Sep 28, 2006 10:32 am
Posts: 1309
Location: Slovakia
Combuster wrote:
Quote:
DOSSEG

Any reason for using that obsolete OS?


DOS is not obsolete and it still is used, http://www.freedos.org/ ;)

_________________
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 8:45 am 
Offline
Member
Member

Joined: Wed Apr 02, 2008 8:36 am
Posts: 27
i want to know what is the function of this code?what does it do?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 8:51 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Some Clues:

Quote:
Code:
; stopwatch

...
Code:
Instructions db 'STOPWATCH',13,10
db '---------',13,10
db ' (S)tart S(t)op (Q)uit',13,10

...


This is very well (over)commented code.

Cheers,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 12:58 pm 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
steward wrote:
i want to know what is the function of this code?what does it do?


If you don't know what it does, why on earth would you want to run it? It sounds to me like you don't know what you're doing... :roll:

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 2:34 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 22, 2007 12:47 pm
Posts: 1598
Location: New Hampshire, USA
if you didnt know what it was, why even grab the code? how did you even get the code if you were searching for nothing imparticular? just random archive somewhere?

that seems like a rather inefficient way to learn code. It would probably help if you knew what you were looking at before you went rummaging through it, or rather, posting it so others can babystep it for you.

_________________
Website: https://Joscor.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 2:51 pm 
Offline
Member
Member

Joined: Wed Apr 02, 2008 8:36 am
Posts: 27
I want to know ,does it show me the Hardware Spec?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], SemrushBot [Bot] and 123 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group