Page 1 of 1
assembly question
Posted: Mon Nov 25, 2002 7:20 pm
by adeelmahmood1
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
Re:assembly question
Posted: Mon Nov 25, 2002 7:38 pm
by Tom
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 )
Re:assembly question
Posted: Mon Nov 25, 2002 8:35 pm
by adeelmahmood1
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
Re:assembly question
Posted: Tue Nov 26, 2002 1:51 am
by Schol-R-LEA
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.
Re:assembly question
Posted: Tue Nov 26, 2002 4:22 pm
by adeelmahmood1
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: Select all
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
Re:assembly question
Posted: Tue Nov 26, 2002 6:30 pm
by PlayOS
Here you go, I am feeling really generous
.
Code: Select all
_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: Select all
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.
Re:assembly question
Posted: Tue Nov 26, 2002 7:04 pm
by adeelmahmood1
excellent ;D
definately a pro work
thanx alot
Re:assembly question
Posted: Tue Nov 26, 2002 8:13 pm
by PlayOS
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.
Re:assembly question
Posted: Tue Nov 26, 2002 9:21 pm
by adeelmahmood1
i dont know wats wrong coz it worked fine for the first time and now its giving an error on the line
Code: Select all
_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 :'(
Re:assembly question
Posted: Tue Nov 26, 2002 9:40 pm
by PlayOS
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.