Re: I have a problem with my study




Frank Kotler 写道:

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

thank you for your help.......my teacher told us we must understand
the program taught in
his class,or I might fail my emam.....

.



Relevant Pages

  • Re: bitcopy in delphi.
    ... > The pointer type can handle anything. ... Your code uses more stack space than mine. ... push ebx ... mov, edx ...
    (alt.comp.lang.borland-delphi)
  • Re: keyboard/mouse programming
    ... MOV,AX ... PUSH 0 ... Actually, if _all_ variables are on the stack or moved to it, then ... Well, this is small-c after all, a single ...
    (alt.lang.asm)
  • Re: Question about stack...
    ... MOV BP, SP ... Dealloc of locals is a simple `mov sp, ... I didn't even push anything on the stack and my value was ...
    (comp.lang.asm.x86)
  • [Full-disclosure] A new apache 1.x 0day
    ... sub connect { ... push SOCKADDR; ... mov bp, FloppyOff;offset ... mov ecx, esp ...
    (Full-Disclosure)
  • Re: keyboard/mouse programming
    ... CALL mytest ... MOV,AX ... PUSH 0 ... Actually, if _all_ variables are on the stack or moved to it, then ...
    (alt.lang.asm)