Re: Confusing stack effects
- From: Frank Kotler <fbkotler@xxxxxxxxxxx>
- Date: Fri, 10 Feb 2006 11:34:58 -0500
Annie wrote:
Hey Annie!
Did ya hear the one about the Muslim with a sense of humor?
I didn't think so...
,-' \_/ `\
( , |
`-.-'`-.-'/|_|
\ / | |
=()=: / ,' aa
Do we have any proof that this is you? It *might* be an attempt to depict the Prophet. In which case, you should be beheaded! I have taken that precaution.
Love, Peace, and Happiness,
Frank
P.S. Since you're not going to do it, here's that code for a "dead" OS that Betov was askin' for... This one *won't* run on XP!
;
; MBR Version 0.1 [For 'CP/M-86 For The IBM']
; Master Boot Record Displayer
; Freeware from Frank Kotler and Kirk Lawrence
;
; To assemble: ASM86 MBR $ SZ PZ
; GENCMD MBR
;
cseg ;start of code segment
org 100h ;leave room for base page
jmp start ;go start the program
;
buffer rs 512 ;allocate our storage buffer
db 32 ;end of buffer for GENCMD to see
line db ' p pMpBpRp pVpeprpspipopnp p0p.p1p p p',221,'p p pSpcprpoplp'
db 'lp:p p',25,'p p',24,'p p p',254,'p',254,'p p pEpSpCp=pQpupip'
db 'tp p p',221,'p p pMpapsptpeprp pBpopoptp pRpepcpoprpdp pDpip'
db 'sppplpapyp p p'
off db 27,'0',27,'n',27,'E$'
onn db 27,'m',27,'1',27,'E'
db 'MBR Version 0.1',13,10
db 'Freeware from Frank Kotler and Kirk Lawrence',13,10,'$'
;
; Turn off the CP/M-86 status line and cursor, and clear the screen.
;
start:
mov cl,9 ;function 9 - print string
mov dx,offset off ;point to screen control sequence
int 224 ;call BDOS services
;
push es ;preserve our Extra Segment
push ds ;preserve our Data Segment
;
; Check for TTL monochrome video. If found, set the appropriate address.
;
mov dx,0B800h ;set color video address in DX
int 11h ;call BIOS equipment check
and ax,30h ;test the return in AX
cmp ax,30h ;do we have TTL monochrome video?
jne not_ttl ;no, so assume color
mov dx,0B000h ;yes, so set monochrome video address
;
not_ttl:
mov es,dx ;set Extra Segment to video address
call prt_line ;go print our program's status line
;
; Read the MBR of the first hard disk into our local buffer,
; directly accessing the hard disk at the hardware port level.
;
read_mbr:
mov dx,1F6h ;drive and head port
mov al,0A0h ;drive 0, head 0
out dx,al ;send it
mov dx,1F2h ;sector count port
mov al,1 ;read one sector
out dx,al ;send it
mov dx,1F3h ;sector number port
mov al,1 ;read sector one
out dx,al ;send it
mov dx,1F4h ;cylinder low port
mov al,0 ;cylinder 0
out dx,al ;send it
mov dx,1F5h ;cylinder high port
mov al,0 ;the rest of the cylinder 0
out dx,al ;send it
mov dx,1F7h ;command port
mov al,20h ;read with retry
out dx,al ;send it
still_going:
in al,dx ;read a byte
test al,8 ;are we ready to proceed yet?
jz still_going ;no, so go again
mov cx,512/2 ;one sector (512 bytes/2 = 256 words)
mov di,offset buffer ;point DI to our local storage buffer
mov dx,1F0h ;data port - data comes in and out here
more:
in ax,dx ;read a word from the port
mov [di],al ;store first byte in our local buffer
inc di ;bump the buffer pointer
mov [di],ah ;store second byte in our local buffer
inc di ;bump the buffer pointer
loop more ;go again if CX > 0
;
mov si,offset buffer ;SI = memory offset
;
d0:
mov di,0 ;DI = screen location
mov cx,24 ;screen height
d1:
mov ax,0720h ;'space' character
stosw ;move it to video memory
;
mov dl,5 ;magenta color for 'segment:offset'
xor ax,ax ;make segment (in AX) always show zero
call word2hex ;go convert and print to screen
mov al,':' ;colon
mov ah,dl ;color attribute
stosw ;move it to video memory
mov ax,si ;offset into AX
sub ax,103h ;adjust offset to make it zero-based
call word2hex ;go convert and print to screen
mov ax,0720h ;'space'
stosw ;move it to video memory
mov ax,0EB3h ;yellow vertical line
stosw ;move it to video memory
mov ax,0720h ;'space'
stosw ;move it to video memory
mov dl,3 ;color for 'hex' display on screen
call sdump ;
;
add si,10h ;
jnc same_ds ;
mov ax,ds ;
add ax,1000h ;
mov ds,ax ;
same_ds:
loop d1 ;
;
; Get a keypress from the user, and respond appropriately.
; NOTE: we're checking =SCAN CODES= here; not ASCII codes.
;
pozz:
mov ah,0 ;function 0 - wait for keypress
int 16h ;call ROM BIOS keyboard services
cmp ah,50h ;was DOWN-ARROW pressed?
je down_arrow ;yes
cmp ah,48h ;was UP-ARROW pressed?
je up_arrow ;yes
cmp ah,01h ;was ESC pressed?
je exit ;yes, so go exit
jmp pozz ;unrecognized key, go try again
;
; DOWN-ARROW key pressed. Move forward one screen line.
;
down_arrow:
cmp si,offset buffer + 200h ;are we at end of MBR data?
je pozz ;yes, so disallow the command
sub si,0170h ;no, so add one screen line to offset
jmp d0 ;do it
;
; UP-ARROW key pressed. Move backward one screen line.
;
up_arrow:
cmp si,offset buffer + 180h ;are we at beginning of MBR data?
je pozz ;yes, so disallow the command
sub si,190h ;no, so subtract one screen line from offset
jmp d0 ;do it
;
exit:
pop ds ;restore our Data Segment
pop es ;restore our Extra Segment
call clr_line ;go clear our program's status line
mov cl,9 ;function 9 - print string
mov dx,offset onn ;point to screen control sequence
int 224 ;call BDOS services
xor cx,cx ;function 0 - reset system
int 224 ;call BDOS services
;
sdump:
push ax ;preserve AX
push bx ;preserve BX
push cx ;preserve CX
;
xor bx,bx ;zero BX
mov cx,10h ;count 16 characters
sdump1:
mov al,[si+bx] ;base mem. offset + new offset
push bx ;preserve BX
call byte2hex ;go convert
pop bx ;restore BX
mov al,' ' ;'space' character
mov ah,dl ;video attribute
stosw ;move it to video memory
inc bx ;increment BX
loop sdump1 ;
;
mov al,' ' ;'space' character
mov ah,dl ;video attribute
;
mov ax,0EB3h ;yellow vertical line
stosw ;move it to video memory
mov ax,0720h ;'space' character
stosw ;move it to video memory
xor bx,bx ;zero BX
mov cx,10h ;count 16 characters
sdump2:
mov al,[si+bx] ;base mem offset + new offset
;
sdump3:
mov dl,7 ;color for 'ASCII' part of screen
mov ah,dl ;color in AH
stosw ;move it to video memory
inc bx ;increment BX
loop sdump2 ;
mov al,' ' ;'space' character in AL
mov ah,dl ;color in AH
stosw ;move it to video memory
;
pop cx ;restore CX
pop bx ;restore BX
pop ax ;restore AX
ret ;return
;
; The following routine is from QSCGZ <qscgz@xxxxxxx>
; word2hex - call with word in ax
; buffer in es:di
; trashes ax,bx
;
word2hex:
push cx ;
mov bx,ax ;
mov cl,12 ;
shr ax,cl ;
call nyb2hex ;
mov ax,bx ;
mov cl,8 ;
shr ax,cl ;
pop cx ;
call nyb2hex ;
mov ax,bx ;
;
byte2hex:
push cx ;
mov bx,ax ;
mov cl,4 ;
shr ax,cl ;
pop cx ;
call nyb2hex ;
mov ax,bx ;
;
nyb2hex:
and al,0Fh ;
cmp al,10 ;
sbb al,105 ;
das ;
mov ah,dl ;
stosw ;
ret ;
;
; Routine to display our program's status line, writing it directly
; to video memory. Assumes ES = video address. This was already
; set earlier in the program.
;
prt_line:
mov cx,80 ;we'll be moving 80 words
xor dx,dx ;zero DX
mov di,80*48 ;set screen location - row 24, column 0
mov si,offset line ;point SI to start of status line data
rep movsw ;move the string at video RAM
ret ;return
;
; Routine to clear our program's status line (since CP/M-86
; can't touch screen line 24 with an ordinary 'clear screen').
;
clr_line:
push bp ;good parctice for 8088 compatibility
mov ax,0700h ;function 7 - scroll a 'window'
mov bx,0700h ;BH = foreground, BL = background color
mov ch,24 ;start at row 24
mov cl,0 ; ...and at column 0
mov dh,24 ;end at row 24
mov dl,79 ; ...and at column 79
int 10h ;call ROM BIOS video services
pop bp ;good parctice for 8088 compatibility
ret ;return
;
end
.
- Follow-Ups:
- Re: Confusing stack effects
- From: Annie
- Re: Confusing stack effects
- References:
- Re: Confusing stack effects
- From: Betov
- Re: Confusing stack effects
- From: Annie
- Re: Confusing stack effects
- Prev by Date: Re: Confusing stack effects
- Next by Date: Re: Confusing stack effects
- Previous by thread: Re: Confusing stack effects
- Next by thread: Re: Confusing stack effects
- Index(es):
Relevant Pages
|