Re: I have a problem with my study
- From: Frank Kotler <spamtrap@xxxxxxxxxx>
- Date: Thu, 19 Oct 2006 16:14:27 -0400
spamtrap@xxxxxxxxxx wrote:
I read a program,but some of my program confuse me
what are these "push ds
sub ax,ax
push ax "
This sets up a (far) return address on your stack.
and "move ah,2" do?
Produces a syntax error? "mov"... well, sets up the subfunction number in ah for the "int 21h" (the "print the character in dl" subfunction), in this case.
prognam segment
main proc far
assume cs rognam
start:
push ds
sub ax,ax
push ax
Put a (far) return address on the stack. When dos loads an .exe file, ds and es are set to the PSP (Program Segment Prefix - a 256 byte data area set up by dos when it loads the program). The first bytes of the PSP are "CD 20" - "int 20h - the "exit to OS" interrupt. Putting the PSP segment and an offset of zero on the stack means that when we do a far "ret", we hit that "int 20h" and return to the command prompt.
At this point, a more extensive program would do:
mov ax, @data
mov ds, ax
To get ds pointed to your data segment... but this program doesn't have one...
mov ch,4
rotate: mov cl,4
rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl printit
add al,7h
printit:
mov dl,al
mov ah,2
int 21h
dec ch
jnz rotate
As you can observe, this displays the contents of bx (represented in hex). Since bx hasn't been explicitly loaded with a value, whatever dos left there will be displayed. If you were interested in es (for example), doing "mov bx, es" before hitting this section would display es.
ret
Calling main "proc far" causes this to be changed to a far "ret", involving cs as well as ip.
Quite honestly, I think you'd be a lot better off to keep everything "in sight". Lose the initial pushes, and end with "int 20h", or (more "modern" way), "mov ah, 4Ch"/"int 21h".
main endp
prognam ends
Best,
Frank
.
- Follow-Ups:
- Re: I have a problem with my study
- From: spamtrap
- Re: I have a problem with my study
- References:
- I have a problem with my study
- From: spamtrap
- I have a problem with my study
- Prev by Date: Re: how can I see the result of the program?
- Next by Date: Re: I have a problem with my study
- Previous by thread: Re: I have a problem with my study
- Next by thread: Re: I have a problem with my study
- Index(es):
Relevant Pages
|