collapse collapse

* Who's Online

  • Dot Guests: 163
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Author Topic: 32bit registers in 16bit!  (Read 9300 times)

0 Members and 1 Guest are viewing this topic.

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
32bit registers in 16bit!
« on: December 27, 2009, 10:10:07 pm »
I actually was helping a student with Assembly and they had an assignment: use 32bit register in some way and use DOS interrupts to output text.

To most of us, we would say not possible but I have figured out a way to do it.

Put .586 at the top of your code and you can use 32bit registers in your 16 applications!

Like this:
Code: [Select]
.586
[asm code...]

Sample code:
Code: [Select]
.model small
 .586
 .stack 200h
 .data
oldvec  dd 0 ;; old interrupt vector
 
.code
 
main    proc
 mov     ax,@data
 mov ds,ax
 
 
 mov ah,35h
 mov al,1Ch   ;; get old interrupt vector for timer  
 int 21h       ;; returns in ES:BX
 mov word ptr [oldvec],bx  ;; save offset
 mov bx,es
 mov word ptr [oldvec+2],bx ;; save segment
 
 mov ah,25h
 mov al,1Ch     ;; use timer interrupt
 mov dx,offset mytmr
 push cs
 pop ds
 int 21h  ;set new 1C interrupt
 
 mov     ax,@data
 mov ds,ax
 ;; do wait...
 mov cx,1000
 call mywait
 
 ;; restore old interrupt vector before exit
 mov dx,word ptr [oldvec]
 mov ax,word ptr [oldvec+2]
 push  ax
 pop ds
 mov ah,25h
 mov al,1ch
 int 21h  
  
 ;; now exit
 Mov ax, 4c00h ;exit to DOS
 Int 21h
 
 
 
main endp

 mytmr proc
  pushad  ;; save all registers (32-bit)
  mov ah,2
  mov dl,'A'
  int 21h
  popad  ;; pop all registers (32-bit)
  iret
 mytmr  endp
 ;; my wait now uses stack for storage, so reentrant.
      CLKFREQ EQU     800 ; clock frequency in MHZ
 TICS_MS EQU CLKFREQ*1000
 ;; will delay # of milliseconds specified in CX. Register CX destroyed
  
 mywait  proc
   push eax
   push edx
   enter 8,0 ;reserve 8 bytes on the stack  
     ;for timer value
 mywaitlp2:
   call timget
   mov [bp-4],eax   ;; save low value
   mov [bp-8],edx   ;; save high value
 mywaitlp1:
   call timget
   sub eax,[bp-4]   ;; subtract low value
   sbb edx,[bp-8]   ;; subtract high value
  ;; edx:eax has delta time. Compare to TICS_MS
   sub eax,TICS_MS
   sbb edx,0
   jc mywaitlp1
   loop mywaitlp2
   leave
   pop edx
   pop eax
   ret
 mywait  endp
; procedure that returns the Pentium+ 64 bit timer value
;  in EDX:EAX
  
 timget  proc
   rdtsc    ;; read timestamp counter
   ret
 timget  endp
 
 end     main
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: 32bit registers in 16bit!
« Reply #1 on: December 27, 2009, 10:54:30 pm »
What does .586 asm do?
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: 32bit registers in 16bit!
« Reply #2 on: December 27, 2009, 11:12:41 pm »
http://msdn.microsoft.com/en-us/library/c9tff918(VS.80).aspx

Quote
.586
Enables assembly of nonprivileged instructions for the Pentium processor.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline isaro

  • Software Developer
  • Administrator
  • Sr. Member
  • *
  • Posts: 393
  • Reputation 505
  • Gender: Male
    • View Profile
Re: 32bit registers in 16bit!
« Reply #3 on: December 30, 2009, 12:25:24 pm »
When I want to accomplish something in ASM I'm going straight to Nathan for help >.>
0001 + 1000 = 1001

Offline icefire

  • Newbie
  • *
  • Posts: 7
  • Reputation 7
    • View Profile
Re: 32bit registers in 16bit!
« Reply #4 on: January 12, 2012, 09:44:14 am »
This assembly language makes me crazy when it is our topic way back on my college class.

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: 32bit registers in 16bit!
« Reply #5 on: January 12, 2012, 09:27:43 pm »
Crazy, but almost required to understand how processors work.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

 

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]