OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 5:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: assembly question
PostPosted: Mon Nov 25, 2002 7:20 pm 
hi
if for example i m using int 62h/AX=0072h to get the size of video memory
it
Returns:
AX = size of video memory in KB
now how can i show this size of vidmem on the
screen..just like we display messages on the screen
thanx for ur help


Top
  
 
 Post subject: Re:assembly question
PostPosted: Mon Nov 25, 2002 7:38 pm 
Yes..but in hex(correct?)...you could use my C/C++ printf in pk0.7.1 ( new release ). ( actually...I got this printf from Chris's Triple Fault site )


Top
  
 
 Post subject: Re:assembly question
PostPosted: Mon Nov 25, 2002 8:35 pm 
well tom i m not talking about C .. i m talking about assembly .. i think i mentioned that too :)
can some one tell me how i can print the hex values in any registers on the screen


Top
  
 
 Post subject: Re:assembly question
PostPosted: Tue Nov 26, 2002 1:51 am 
adeelmahmood1 wrote:
well tom i m not talking about C .. i m talking about assembly .. i think i mentioned that too :)
can some one tell me how i can print the hex values in any registers on the screen

This thread discusses a general algorithm for converting a binary to a string, for any number base.


Top
  
 
 Post subject: Re:assembly question
PostPosted: Tue Nov 26, 2002 4:22 pm 
well actually i dont know .. i have checked that algorithm and i m still confused .. ok let me ask it this way
here is the code to print a msg on the screen
Code:
mov si,msg
print:
           lodsb
           cmp al,0
           je done

          mov ah,0eh
          mov bx,7
          int 10h
          jmp print
done:
           mov ah,4ch
           int 21h

msg db 'hello',13,10,0

ok now if we have '1111000011110000' in and ax and i wanna print that on the screen .. wat should i do
can i do it like

mov si,ax
call print
BTW thanx for ur help


Top
  
 
 Post subject: Re:assembly question
PostPosted: Tue Nov 26, 2002 6:30 pm 
Here you go, I am feeling really generous ;).

Code:
_Num2HexStr:
   PUSH               EBP
   PUSH               EAX
   PUSH               EBX
   PUSH               ECX
   PUSH               ESI
   MOV                EBP, ESP
; === START OPTIONAL CODE ===
.Hexadecimal_Conversion:
   MOV                  ESI, DWORD [EBP + 24]
   MOV                  EBX, DWORD [EBP + 28]
   CMP                  EBX, 0
   JE                   .End_Hex_Conversion_Zero
   MOV                  ECX, 8
.Remove_Lead_Zeros:
   ROL                  EBX, 4
   MOV                  AL, BL
   AND                  BL, 0x0F
   CMP                  BL, 0
   MOV                  BL, AL
   JE                   .Skip_Zero
   JMP                  SHORT .Start_Conversion_Loop
.Skip_Zero:
   DEC                  ECX
   JMP                  SHORT .Remove_Lead_Zeros
.Start_Conversion_Loop:
   ROR                  EBX, 4
; === END OPTIONAL CODE ===
.Conversion_Loop:
   ROL                  EBX, 4
   MOV                  AL, BL
   AND                  AL, 0x0F
   OR                   AL, 0x30
   CMP                  AL, 0x39
   JNA                  .Dont_Add_7
   ADD                  AL, 0x07
.Dont_Add_7:
   MOV                  BYTE [ESI], AL
   INC                  ESI
   DEC                  ECX
   CMP                  ECX, 0
   JE                   .End_Hex_Conversion
   JMP                  SHORT .Conversion_Loop
.End_Hex_Conversion:
   MOV                  BYTE [ESI], 0
   JMP                  .End_Conversion
.End_Hex_Conversion_Zero:
   MOV                  BYTE [ESI], '0'
   MOV                  BYTE [ESI + 1], 0
.End_Conversion:
   POP                  ESI
   POP                  ECX
   POP                  EBX
   POP                  EAX
   POP                  EBP
   RET                  8


This code works as follows:

You must push two parameters onto the stack, first push the number (eax), then push the address of a buffer to place the string in, then call the function, the parameters will be removed for you, if you want to make the function smaller you can remove the code marked as optional, all it does is remove any leading zeros from the number, for example if you passed the number 0x0003dbb4 it would put in the buffer 3dbb4.

Here is an example of its use, you could write a function that would display the contents of eax like this:

Code:
buffer db 0,0,0,0,0,0,0,0,0 ; requires 9 bytes at the most

_Display_EAX:
     push   eax
     push   buffer
     call     _Num2HexStr
     mov    si, buffer
     call     print
     ret


Hope this helps.


Top
  
 
 Post subject: Re:assembly question
PostPosted: Tue Nov 26, 2002 7:04 pm 
excellent ;D
definately a pro work :)
thanx alot


Top
  
 
 Post subject: Re:assembly question
PostPosted: Tue Nov 26, 2002 8:13 pm 
You are very welcome, also if you decided to leave the optional code in there, then you should recopy the code from above, because I was looking at the code again and I noticed a way to save 10+ bytes and 25+ clock cycles, so it was quite a big optimization, I edited the code in place so just recopy it and replace the old version with the new one above.


Top
  
 
 Post subject: Re:assembly question
PostPosted: Tue Nov 26, 2002 9:21 pm 
i dont know wats wrong coz it worked fine for the first time and now its giving an error on the line
Code:
_Display_EAX:
    push  eax
    push  buffer      ============>>> error
    call    _Num2HexStr
    mov    si, buffer
    call    print
    ret

error: operation size not specified
can u see wats going on :'(


Top
  
 
 Post subject: Re:assembly question
PostPosted: Tue Nov 26, 2002 9:40 pm 
This error means that nasm isn't sure of what size you are working with, just change

push buffer

to

push dword buffer

and all should go well.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 48 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