x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 4556
Number of posts: 16011

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
[advise please] unable to run 16bit macro in 32bit masm. [thank you] Posted by cielle on 26 Sept 2008 at 11:27 AM
hi al,

I would like to asking for advises regarding on the application of macros in 32bit masm.

i have 3 macro as shown below. These macros function smoothly when i apply them in masm 16 bit. Yet, when i tried to apply the same macros in masm 32-bit, program is forced to be terminated (window error occur).

What should i modify on the macros so that they are application in masm 32 bit? and what is the reason of these problem? Isn't macro should be applicable for either 16 or 32 bits?


*************************macros************************

;-------------------- macro to clear part --------------------
CLEAR MACRO start_xy, end_xy
mov ax,0600H
mov cx,start_xy
mov dx,end_xy
mov bh,7
int 10h
mov ah,2
mov bh,0
mov dx,0
int 10h
ENDM

;----------------- macro to set colour window ----------------
SET_WINDOW MACRO COLOUR, START_XY, END_XY
mov ax,0600h ; scroll window
mov bh,COLOUR ; background, font
mov cx,START_XY ; coordinate start point
mov dx,END_XY ; coordinate end point
int 10h
ENDM

;---------------- macro to produce end of line ----------------
ENDL MACRO
mov ah,2
mov dl,CR
int 21h
mov ah,2
mov dl,LF
int 21h
ENDM




Thanks for your reply.:)

cielle

Report
Re: [advise please] unable[thank you] Posted by jeffleyda on 26 Sept 2008 at 12:10 PM
you cannot call INT functions from win32. win32 is protected mode, INT functions are real mode.


Report
Re: [advise please] unable[thank you] Posted by cielle on 27 Sept 2008 at 1:22 AM
: you cannot call INT functions from win32. win32 is protected mode,
: INT functions are real mode.
:
:
:


Thanks for your prompt reply.

So is that means that there is no way for me to apply those macros in 32bit?

If so is how should i modify the existing (found in masm32 include file)

(i) clearscreen proc so that i can clear part of the screen but not the entire screen? s
(ii)settextcolour proc so that i can set the background colour depends on my desired area but not only the area with string?


Thank u again..
Report
Re: [advise please] unable[thank you] Posted by AsmGuru62 on 27 Sept 2008 at 4:37 AM
: : you cannot call INT functions from win32. win32 is protected mode,
: : INT functions are real mode.
: :
: :
: :
:
:
: Thanks for your prompt
: reply.

:
: So is that means that there is no way for me to apply those macros
: in 32bit?
:
: If so is how should i modify the existing (found in masm32 include
: file)
:
: (i) clearscreen proc so that i can clear part of the screen but not
: the entire screen? s
: (ii)settextcolour proc so that i can set the background colour
: depends on my desired area but not only the area with string?
:
:
: Thank u again..
:

In Windows to work on console window you need console API calls from that list:

http://msdn.microsoft.com/en-us/library/ms682073(VS.85).aspx
Report
Re: [advise please] unable[thank you] Posted by cielle on 28 Sept 2008 at 12:21 AM
thanks for your prompt reply.

But wat should i do to achieve the purpose to set the colour for desired area only but not on the GUI application?

actually, i would like to write a program which is all about piano keyboard tutorial. i nid the respective key to be coloured when its respective note is played.

But now the problem is i can;t implement the macro which i usually use in 16 masm to set certain area of background colour.

i have to use 32 masm due to vista can;t play the frequency smoothly in 16 bits. I have to apply finale software to give me the music output.



realy many thanks on your advise.
Report
Re: [advise please] unable[thank you] Posted by AsmGuru62 on 28 Sept 2008 at 5:18 AM
: thanks for your prompt reply.
:
: But wat should i do to achieve the purpose to set the colour for
: desired area only but not on the GUI application?
:
: actually, i would like to write a program which is all about piano
: keyboard tutorial. i nid the respective key to be coloured when its
: respective note is played.
:
: But now the problem is i can;t implement the macro which i usually
: use in 16 masm to set certain area of background colour.
:
: i have to use 32 masm due to vista can;t play the frequency smoothly
: in 16 bits. I have to apply finale software to give me the music
: output.
:
:
:
: realy many thanks on your advise.
:
Strange... the link from my post does not work. Did you try to go by the link by copying it into browser?

Anyhow,

The function you need is here:

http://msdn.microsoft.com/en-us/library/ms682662(VS.85).aspx

Say, you have the area of text on a console window and you need to set the background for the area to some specific color - to highlight it. You need to use this function on each row of text from that area.
Report
Re: [advise please] unable[thank you] Posted by cielle on 28 Sept 2008 at 9:26 PM
Thank you ASMGURU.

i have study a bit of the function from the link given by you.
Yet i need to put more effort to understand it as i m not that familiar with masm32 bit.
Previously only deal with masm16.

Lets say i wish to set the color for area start with coordinate 0010h until 0439h. Is it possible for me to do that by using FillConsoleOutputAttribute Function? as i notice its decription says that colour only cover area which contain string with it. But my purpose is colour the background on my own desired area.

I can set the background colour start with coordinate 0010h until 0439h by using the macros below.

SET_WINDOW MACRO COLOUR, START_XY, END_XY
mov ax,0600h ; scroll window
mov bh,COLOUR ; background, font
mov cx,START_XY ; coordinate start point
mov dx,END_XY ; coordinate end point
int 10h
ENDM



Yet i can't use this bcoz it is in real mode.
Masm32 run in protected mode.

But can i modify the macro so that it can run in masm32?
If that is impossible, i will try hard to understand the FillConsoleOutputAttribute.

Sorry that if i kips on repeating the question as i m still have to digest the link that given by ASMGURU.

MASM32 is confusing... -.-!!

Thanks again!!!

Regards,
CIelle
Report
Re: [advise please] unable[thank you] Posted by AsmGuru62 on 29 Sept 2008 at 3:59 AM
: Thank you ASMGURU.
:
: i have study a bit of the function from the link given by you.
: Yet i need to put more effort to understand it as i m not that
: familiar with masm32 bit.
: Previously only deal with masm16.
:
: Lets say i wish to set the color for area start with
: coordinate 0010h until 0439h. Is it possible for
: me to do that by using FillConsoleOutputAttribute Function? as i
: notice its decription says that colour only cover area which contain
: string with it. But my purpose is colour the background on my own
: desired area.
:
: I can set the background colour start with coordinate 0010h until
: 0439h by using the macros below.
:
: SET_WINDOW MACRO COLOUR, START_XY, END_XY
:

: mov ax,0600h ; scroll window
: mov bh,COLOUR ; background, font
: mov cx,START_XY ; coordinate start point
: mov dx,END_XY ; coordinate end point
: int 10h
: ENDM

:
:
: Yet i can't use this bcoz it is in real mode.
: Masm32 run in protected mode.
:
: But can i modify the macro so that it can run in masm32?
: If that is impossible, i will try hard to understand the
: FillConsoleOutputAttribute.
:
: Sorry that if i kips on repeating the question as i m still have to
: digest the link that given by ASMGURU.
:
: MASM32 is confusing... -.-!!
:
: Thanks again!!!
:
: Regards,
: CIelle
:

I see, when you say coordinate - you mean the row,col pair of values stored in a register.

In short, you need a new macro, even better - a new function, because macro will be quite long, because it will be a loop.

So, lets look at FillConsoleOutputAttribute():

invoke	FillConsoleOutputAttribute, hConsole, color,\
	nChars, coord, addr dwFilled


hConsole = a handle to Console returned by call to GetStdHandle().
color = an attribute you want to apply on console characters.
nChars = how many characters you want to highlight.
coord = row,col of a location you want to begin highlighting.
dwFilled = a DWORD variable which will be set to real character count of filled characters. Usually not used - just pass some address.

Example: you need to highlight a rectangle with:

left column = 10
top row = 4
right column = 50
bottom row = 12

You need to call the function for each row in that rectangle. Number of rows = 1+(12-4) = 9. nChars parameter is a rectangle width = 1+(50-10) = 41. So, you need a loop of 9 times and you need to pass the proper coord parameter for each row.
Report
Re: [advise please] unable[thank you] Posted by cielle on 29 Sept 2008 at 8:25 AM
Hi ASMGURU. Thanks for your explaination.

I tried to implement the function. Code can be assemble. Yet it shows nthg.

I tried to get a rectangle manualy (without using loop) for 1st trial.
Yet i failed. Below is my code. Kindly advise me pls where is my mistake
.

.486
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\advapi32.inc ; needed for Registry functions
include C:\Masm32\INCLUDE\masm32.inc
include C:\Masm16\INCLUDE\winmm.inc ; multimedia for music playback

include C:\Masm615\INCLUDE\macros.asm ; MASM support macros

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\advapi32.lib ; needed for Registry functions

includelib C:\Masm16\lib\masm32.lib
includelib C:\Masm16\lib\winmm.lib ; multimedia for music playback



.code
main:

;invoke FillConsoleOutputAttribute, hConsole, color,\nChars, coord, addr dwFilled

invoke FillConsoleOutputAttribute, 1, 2, 7, 0306h, 4
invoke FillConsoleOutputAttribute, 1, 2, 7, 0406h, 4
invoke FillConsoleOutputAttribute, 1, 2, 7, 0506h, 4

invoke ExitProcess,0

end main


I had tried to surf net for further explanation. But i failed to get a proper example which show the proper way of application of FillConsoleOutputAttribute proc.


Thanks for giving and correct my mistake!

Regards,
Cielle


Report
Re: [advise please] unable[thank you] Posted by anthrax11 on 29 Sept 2008 at 3:34 PM
Don't try to link 16-bit stuff to 32-bit, it won't work.

You almost had the FillConsoleOutputAttribute call right, but not quite :)
Also, you need a handle to the console, try this:

.486
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

.data
hConsole HANDLE ?
dwFilled dd ?

.code
main:

invoke  GetStdHandle, STD_OUTPUT_HANDLE
mov hConsole, eax

invoke  FillConsoleOutputAttribute, hConsole, FOREGROUND_GREEN, 7, 00030006h, addr dwFilled
invoke  FillConsoleOutputAttribute, hConsole, FOREGROUND_GREEN, 7, 00040006h, addr dwFilled
invoke  FillConsoleOutputAttribute, hConsole, FOREGROUND_GREEN, 7, 00050006h, addr dwFilled

invoke ExitProcess, 0

end main
Report
Re: [advise please] unable[thank you] Posted by cielle on 29 Sept 2008 at 9:26 PM
hi!

i tried with your code d..

But it still give no output on the exe file.

Wrong is the problem pls?

Thanks for your advise again..
Report
Re: [advise please] unable[thank you] Posted by cielle on 29 Sept 2008 at 9:46 PM
Hi. Below is my another way of getting the highlighted area with sepecific coloum and row. Yet i found that my music wav file can run with the set area colour procedure.

.486
.model flat,stdcall
option casemap : none

include\masm32\include\windows.inc
include\masm32\macros\macros.asm

include\masm32\include\masm32.inc
include\masm32\include\gdi32.inc
include\masm32\include\user32.inc
include\masm32\include\kernel32.inc
include\masm32\include\winmm.inc ;windows multimedia library

includelib\masm32\lib\masm32.lib
includelib\masm32\lib\gdi32.lib
includelib\masm32\lib\user32.lib
includelib\masm32\lib\kernel32.lib
includelib\masm32\lib\winmm.lib ;windows multimedia library

.data

xCor dd ?
yCor dd ?

cMajorWav db "c major.wav",0 ; wave file name

.code

SetCellColor proc fore:DWORD,back:DWORD,x:DWORD,y:DWORD
LOCAL hOutPut:DWORD
LOCAL noc :DWORD
LOCAL coord :DWORD

invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hOutPut, eax
mov edx,back
shl edx,4
or edx,fore
mov ecx, x
mov eax, y
shl eax, 16
mov ax, cx
mov coord,eax
mov ecx,1
invoke FillConsoleOutputAttribute,hOutPut,edx,ecx,coord,ADDR noc
ret
SetCellColor endp


playC proc
mov xCor,2
mov yCor,5

.while yCor<=10
mov xCor,15
.while xCor<=25
invoke SetCellColor,15,12,xCor,yCor
inc xCor
.endw
inc yCor
.endw
playC endp


start:

invoke PlaySound,ADDR cMajorWav,NULL,SND_FILENAME+SND_ASYNC ; play sound file
call playC
invoke Sleep,10000
invoke locate,4,21

exit

end start



Kindly advise my mistake please..

Regards,
Cielle

























Report
Re: [advise please] unable[thank you] Posted by AsmGuru62 on 30 Sept 2008 at 2:41 AM
After calling these coloring functions the ExitProcess gets called immediately, so you do not see the results. You need to make a full console application with user input and such or put "invoke Sleep, 10000" before ExitProcess.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.