Hi,
Following program is working fine without macro:
;----------------------------------------------------------------------------------
.MODEL TINY
.data
msg db "We be bootin2'!",0
.CODE
;----------------------------------------------------------------------------------
ORG 0
;code branch
boot0: jmp short boot1
;----------------------------------------------------------------------------------
ORG 3
;OEM identifier
boot03 db 'BootDisk' ;always 8 characters
.STACK 2048; removes the stack warning
;----------------------------------------------------------------------------------
ORG 0Bh
boot0B dw 200h ;bytes per sector
boot0D db 1 ;sectors per cluster
boot0E dw 1 ;reserved sectors (the boot sector is reserved)
boot10 db 2 ;number of copies of the FAT
boot11 dw 0E0h ;root directory entries (224 for 1.4 mb)
boot13 dw 0B40h ;total disk sectors
boot15 db 0F0h ;media descriptor byte (F0 for 1.4 mb)
boot16 dw 9 ;sectors per FAT
boot18 dw 12h ;sectors per cylinder
boot1A dw 2 ;number of heads
boot1C dw 0 ;hidden sectors
xCursor db 0
yCursor db 0
;----------------------------------------------------------------------------------
boot1: cli ;disable maskable interrupts
xor di,di
mov ss,di
mov sp,7C00h ;SS:SP = 0000:7C00
XOR AX,AX ;Makes AX=0.
MOV ES,AX ;Make ES=0
mov DS,ax
sti
mov ax,0B800h ;notice that di is already 0
mov es,ax
cld
mov ax,1F41h
stosw
;----------------------------------call procedures
CALL GetKey ;Call GetKey()
Call ClearScreen ;ClearScreen()
LEA AX,msg ;Get Address of szReady.
CALL PrintMessage ;Call PrintfMessage()
boot2: jmp boot2
;-------------------------------------procedure definitions
GetKey PROC near
mov ah,0
int 16h ;Wait for a key press.
Ret
GetKey EndP
ClearScreen PROC near
mov ax,0600h ;//Scroll All Screen UP to Clear Screen.
mov bh,07
mov cx,0
mov dx,184fh
int 10h
Mov byte ptr xCursor,0 ;//Set Cursor Position So next
;//write would start in
;//the beginning of screen.
Mov byte ptr yCursor,0
Ret
ClearScreen EndP
PrintMessage PROC near
xor di,di
mov ds,di
mov ax,0B800h
mov es,ax
; should probably set up a sane stack here, too.
mov si,offset msg ; "our dear string"
mov ah,04h ; color
msgloop:
lodsb ;loads AL with a byte of data from mem location pointed by SI
or al,al
jz blackhole
stosw ; transfers the contents of AL to the mem location pointed by di
jmp msgloop
blackhole: ret
PrintMessage EndP
;----------------------------------------------------------------------------------
ORG 1FEh
;validation marker
dw 0AA55h
;----------------------------------------------------------------------------------
END boot0
but when I add a macro in this program, I am not getting any string displayed. The new program after induction of
macro is given below:
;----------------------------------------------------------------------------------
print_mesg macro offset1
mov ax,7C0h
mov ds,ax
push ax
mov ax,xlat0
push ax
retf
;at this point, the registers are as follows:
;DI = 0000
;CS = DS = 07C0
;IP = xlat0 offset
;SS:SP = 0000:7C00
;display the message at B800:0000
xlat0: mov ax,0B800h ;notice that di is already 0
mov es,ax
mov si,offset offset1
cld
mov ah,1Fh
mov cx,sizeof offset1
disp0: lodsb
stosw
loop disp0
endm
.MODEL TINY
.CODE
;----------------------------------------------------------------------------------
ORG 0
;code branch
boot0: jmp short boot1
;----------------------------------------------------------------------------------
ORG 3
;OEM identifier
boot03 db 'BootDisk' ;always 8 characters
.STACK 2048; removes the stack warning
;----------------------------------------------------------------------------------
ORG 0Bh
boot0B dw 200h ;bytes per sector
boot0D db 1 ;sectors per cluster
boot0E dw 1 ;reserved sectors (the boot sector is reserved)
boot10 db 2 ;number of copies of the FAT
boot11 dw 0E0h ;root directory entries (224 for 1.4 mb)
boot13 dw 0B40h ;total disk sectors
boot15 db 0F0h ;media descriptor byte (F0 for 1.4 mb)
boot16 dw 9 ;sectors per FAT
boot18 dw 12h ;sectors per cylinder
boot1A dw 2 ;number of heads
boot1C dw 0 ;hidden sectors
xCursor db 0
yCursor db 0
;----------------------------------------------------------------------------------
boot1: cli ;disable maskable interrupts
xor di,di
mov ss,di
mov sp,7C00h ;SS:SP = 0000:7C00
XOR AX,AX ;Makes AX=0.
MOV ES,AX ;Make ES=0
mov DS,ax
sti
mov ax,0B800h ;notice that di is already 0
mov es,ax
cld
mov ax,1F41h
stosw
;----------------------------------call procedures
CALL GetKey ;Call GetKey()
Call ClearScreen ;ClearScreen()
LEA AX,msg ;Get Address of szReady.
CALL PrintMessage ;Call PrintfMessage()
CALL GetKey
print_mesg msg
boot2: jmp boot2
;-------------------------------------procedure definitions
msg2 db "Zulfi We be bootin2'!"
msg db "We be bootin2'!",0
GetKey PROC near
mov ah,0
int 16h ;Wait for a key press.
Ret
GetKey EndP
ClearScreen PROC near
mov ax,0600h ;//Scroll All Screen UP to Clear Screen.
mov bh,07
mov cx,0
mov dx,184fh
int 10h
Mov byte ptr xCursor,0 ;//Set Cursor Position So next
;//write would start in
;//the beginning of screen.
Mov byte ptr yCursor,0
Ret
ClearScreen EndP
PrintMessage PROC near
xor di,di
mov ds,di
mov ax,0B800h
mov es,ax
; should probably set up a sane stack here, too.
mov si,offset msg ; "our dear string"
mov ah,04h ; color
msgloop:
lodsb ;loads AL with a byte of data from mem location pointed by SI
or al,al
jz blackhole
stosw ; transfers the contents of AL to the mem location pointed by di
jmp msgloop
blackhole: ret
PrintMessage EndP
;----------------------------------------------------------------------------------
ORG 1FEh
;validation marker
dw 0AA55h
;----------------------------------------------------------------------------------
END boot0
Can somebody plz help me with this?
Zulfi.
i am not sure why you want all those PROCs (and macros for that matter)
most of the PROCs you have are only called once - that adds 4 bytes each
GetKey is the only one that makes sense, as it is called twice
even then, mov ah,0;int 16h is only 4 bytes
a call is 3 bytes and a ret is 1 byte, so you aren't saving any space unless you use it at least 5 times
what you have now is 2 call's (6 bytes) and the mov ah,0;int 16h (4 bytes) with a ret (1 byte) - total 11 bytes
if you just put in mov ah,0;int 16h twice - total 8 bytes
as for macros, a boot sector, as well as ROMable code, is just no place for a macro
you are trying to conserve precious real-estate
Hi,
Boot sector is of 512 bytes so why we cant have a macro in it??
Zulfi.
well, you can
but, that 512 bytes can be precious space when it comes time to
add the code to locate the boot-loader and load it from the floppy
macros are used to repeat sections of code whenever the name is typed
they are a great time-saver in normal programming
but, in this case, we do not to want repeat sections of code
the code that you originally wanted to put into a macro was the display-text code
no need to repeat that code several times - i.e. no need for it to be in a macro
Ok, I am just doing an experiment. I can remove macro but I dont know what problem is being caused by this macro in displaying mesg?
Zulfi.
first, when you define a macro, that definition does not generate any code
the definition must appear before it is referenced
so, to make a simple macro, place it near the beginning of the file (after the .model, but before a segment is opened)
.MODEL TINY
;------------------------------------------------------------------------
PrintMessage MACRO
xor di,di
mov ax,0B800h
mov es,ax
mov ah,04h ; color
msgloop:
lodsb
or al,al
jz msgdone
stosw
jmp msgloop
msgdone:
ENDM
;------------------------------------------------------------------------
.DATA
;
Message1 db 'Hello World',0
;
.CODE
;
;
;
;
mov si,offset Message1
PrintMessage
DeadLoop: jmp DeadLoop
you can also pass arguments to the macro
so, if you define the macro as
PrintMessage MACRO MessageAddr:REQ
mov si,MessageAddr
.
.
you can now use the macro like this:
PrintMessage offset Message1
if you look at the file \masm32\help\asmintro.chm
read the section "Working with Macros"
all of this is explained in there, including more ways to pass arguments