From: Genady Beryozkin Newsgroups: comp.os.msdos.djgpp Subject: A little problem with the assembler Date: Thu, 16 Oct 1997 09:21:55 +0200 Organization: The Technion Lines: 139 Message-ID: <3445C093.F9B18043@t2.technion.ac.il> NNTP-Posting-Host: 192.115.49.16 Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------BD829E12C14A53F7D5F51F5F" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk This is a multi-part message in MIME format. --------------BD829E12C14A53F7D5F51F5F Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello ! Recently I've been converting a cpp file, which uses a Borland 16bit inline assembler, into a 32bit djgpp code. Well, after carefully converting each instruction, it still didn't work. The module is intended to measure time with some super-high accuracy (of 1 nanosecond) and I desparately need it to work under djgpp. The source is at the bottom of this message. If you could please take a look at the code (it's a really short code) and help me converting it, I'd be much grateful. If anybody know about any other code which compiles under gcc, and does the same, please write me. Thanks in advance Genady c0467082 AT t2 DOT technion DOT ac DOT il // ------------- tctimer.cpp -------------------- #define __DPMI32__ #include #undef outportb const TimerResolution=1193181.667; void cardinal(long l,double *result) // internal function - works ok. { *result = ((l<0)?4294967296.0 + (long)l : (long)l); } void elapsedtime(long start, long stop, double *result) // works ok. { double r; cardinal(stop - start, &r); *result = (1000.0 * r) / TimerResolution; } void initializetimer(void) // troubles start here .... { // HELP !!!!!!!!!!!!!!1 outportb(0x043,0x034); asm jmp short NullJump1 NullJump1:; outportb(0x040,0x000); asm jmp short NullJump2 NullJump2:; outportb(0x040,0x000); } void restoretimer(void) { outportb(0x043,0x036); asm jmp short NullJump1 NullJump1:; outportb(0x040,0x000); asm jmp short NullJump2 NullJump2:; outportb(0x040,0x000); } long readtimer(void) // ok - this is the most problematic code. // please notice the DOS memory access below (at 0040:006C) // also here the function returns a "long" result in DX:AX // (borland) { asm cli /* Disable interrupts */ asm mov dx,020h /* Address PIC ocw3 */ asm mov al,00Ah /* Ask to read irr */ asm out dx,al asm mov al,00h /* Latch timer 0 */ asm out 043h,al asm in al,dx /* Read irr */ asm mov di,ax /* Save it in DI */ asm in al,040h /* Counter --> bx*/ asm mov bl,al /* LSB in BL */ asm in al,040h asm mov bh,al /* MSB in BH */ asm not bx /* Need ascending counter */ asm in al,021h /* Read PIC imr */ asm mov si,ax /* Save it in SI */ asm mov al,00FFh /* Mask all interrupts */ asm out 021h,al asm mov ax,040h /* read low word of time */ asm mov es,ax /* from BIOS data area */ asm mov dx,es:[06Ch] asm mov ax,si /* Restore imr from SI */ asm out 021h,al asm sti /* Enable interrupts */ asm mov ax,di /* Retrieve old irr */ asm test al,001h /* Counter hit 0? */ asm jz done /* Jump if not */ asm cmp bx,0FFh /* Counter > 0x0FF? */ asm ja done /* Done if so */ asm inc dx /* Else count int req. */ done:; asm mov ax,bx /* set function result */ } --------------BD829E12C14A53F7D5F51F5F Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Genady Beryozkin Content-Disposition: attachment; filename="vcard.vcf" begin: vcard fn: Genady Beryozkin n: Beryozkin;Genady org: The Technion adr: ;;;Natzrat Illit / Haifa;;;Israel email;internet: c0467082 AT t2 DOT technion DOT ac DOT il note: Homepage : http://t2.technion.ac.il/~c0467082/ x-mozilla-cpt: ;0 x-mozilla-html: FALSE version: 2.1 end: vcard --------------BD829E12C14A53F7D5F51F5F--