Re: simple 47 bits newbe ;_0
- From: Frank Kotler <fbkotler@xxxxxxxxxxx>
- Date: Wed, 12 Sep 2007 14:06:46 GMT
Jean Pierre Daviau wrote:
Thanks for your attention.
Heh! I replied to this... Maybe I didn't answer your questions, and maybe you didn't see it (news servers aren't always reliable). In any case, I'll repeat it. If I'm not answering your questions, try explaining again what you want to do...
[repost]
Jean Pierre Daviau wrote:
> Thanks for your attention.
> I compiled your program with nasm easily and runned it with pleasure. :-)
>
> Then I bang ed my head on my little thing.
>
> 0DF2:0230 -0p-0pp-ai-09$
> 0DF2:0240 -0p-0pp$
> 0DF2:0250 -ai-09$
> 0DF2:0260 Your input passw
> 0DF2:0270 ord is no good ;
> 0DF2:0280 -($"............
> 0DF2:0290 Your password is
> 0DF2:02A0 good enough :-)$
>
> mov ax,0240
> mov bx,0250
> add ax,[bx]
Okay... ax is 240h + "-a", I guess - 636Dh?
> mov ah,09
ax = 96Dh
> int 21
??? What's dx at this point?
> nops
> cmp ax,0230
> jnz 011b
Highly unlikely to be 230h!
> --- 11 b -- xor ax,ax
> nops
> mov ax,0260
> mov ah,09
> nops
> int 21
> xor ax,ax
> mov ax,0190
> mov ah,09
> nop
> int 21
> int 20
No idea what this is intended to do.
> ---------------
> some question arises.
>
> How the int 21 knows that it has to print the ax register and not the bx or dx or else register?
If ah=9, int 21h prints the '$'-terminated string pointed to by dx. I'm not aware of a dos function that prints the ax, bx or dx registers - that can be "arranged", if that's what we want, but not with an existing int 21h function.
> 17CF: 0100 B8 40 01
> segment offset opcodes
> Is that it?
Yes... if I understand the question.
> -----------------
> mov ax,0240
The above is "mov ax, 140h", though. This one would be B8 40 02
> mov bx,0250
>
> I tried to
> mov bl, text2
In 16-bit code "text2" is a 16-bit address(offset). It won't fit in bl - Nasm loads the low byte into bl.
> add ax, [bl] assembler complains
Not a valid effective address. No such instruction exists on x86. Nasm couldn't possibly do it for ya.
> mov bh, text2
> add ax, [bh] assembler silent
Well, that's a bug! Says "error: invalid effective address" to me.
> In the bytes are the characters placed from left to right?
Depends on whether you're looking at the computer from the top or the bottom. :)
From low memory to high memory. Generally it would be written with the low addresses at the left, but that isn't a law.
> hello
>
> 1 2 3 4 5 6 7 8 - 1 2 3 4 5 6 7 8
> h e l l o
>
> world
> 1 2 3 4 5 6 7 8 - 1 2 3 4 5 6 7 8
> w o r l d
>
> ax + dx would be a 32 bites word
No. Sometimes ax and dx are used together - dx * 65536 + ax - commonly written "dx:ax". But ax + dx, assuming "+" means "add", would still be 16 bits. If the result won't fit in 16 bits, it "wraps around" - 0FFFFh + 1 = 0 - the carry flag indicates that this has happened.
> or the assembler 'compress' it in two bytes ?
> 1 2 3 4 5 6 7 8 - 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 - 1 2 3 4 5 6 7 8
> h e l l o world
Are you trying to concatenate two strings???
> Here bx is allowed in between [] but not dx.
> mov bx, text2
> add ax, [bx]
Correct. 16-bit effective addresses can use bx, si, di, bp. Even in 16-bit code, you can use 32-bit instructions (not in DEBUG). "mov ax, [edx]" would be a valid effective address. If the high word of edx were not zero, this would exceed the "limit" for our segment (0FFFFh) and cause an exception, but that's a different issue.
> ------------------ nasmpsw.asm ------------------------
> ;nasm nasmpsw.asm -f bin -onasmpsw.com
> org 100
>
> label:
> mov ah,09h
> int 21h
> ret
Print "???" and exit...
(maybe I should explain how "ret" exits a .com file. As you know (?), "call" puts the return address on the stack, "ret" finds the return address on the stack, and goes there. When dos loads a .com file, it pushes a zero on the stack, so when the .com file gets to "ret" it goes to offset 0 in whatever segment we're in (decided by dos when it loads us). You've noticed that our program starts at 100h - what's in that first 100h bytes? The "program Segment Prefix", or "PSP". Mostly it's not instructions, but the very first two bytes are CD 20 - the instruction "int 20h" - which exits to the OS. This *only* applies to ..com files!)
> mov ax, text1
> mov bx, text2
> add ax, [bx]
> mov ah, 09h
> int 21h
Still nothing sane in dx. Print more "???".
> cmp ax, text3
Unlikely to be true.
> jmp label
Go back to "print ??? and exit"... except that we never get here 'cause we exited the first time.
> xor ax, ax
> mov ax, text4
Do you mean to be doing "mov DX, ..." here?
> mov ah,09
> int 21h
>
> xor ax,ax
> mov ax, text5
> mov ah,09h
> int 21h
> int 20h
>
>
> text1 db "-0p-0pp$"
> text2 db "-ai-09$"
> text3 db "-0p-0pp-ai-09$"
> text4 dw "Your password is no good ;-)$"
> text5 dw "Your password is so good ;-)$"
>
> ---------------------------------
>
> in both cases I have something like that:
> ???óÓ?Ú¾ ©? ?? 3? 2
> 6Û?¾ñì>? ^?? ë>? PîÏ
>
> -------------
>
> If all this is too simplistic for the group telll me.
No! We're busy with our "wars" - sorry for the delay - but these are good questions to be asking! You seem to be misunderstanding something "simple"... not "simple" if you don't understand it! Once you understand it, it'll be "simple". You seem to be mixing putting the address of a string in a register, and putting the (partial) contents of the string in a register. They don't mix well. :(
If *I* understand it, you want to have the password in the file in two pieces, and "add 'em together" to compare to what the user enters. (?) Adding the addresses together won't do that! You need a "strcat" routine. Betov, what's French for "concatenate"?
You seem to have the two "pieces of password" terminated with '$'. This would be good if you wanted to print 'em with in21h/9, but not helpful to "concatenate" them. Lemme try something simple, and see if this is what you need... (I'll continue to use '$')
org 100h
mov si, part1 ; address of first password part
mov di, whole ; address of buffer to combine strings
first_part:
mov al, [si] ; contents of string
inc si ; ready for nect one - could use "lodsb"
; if it's the '$', we're done with this part - don't copy it!
cmp al, '$'
je second_part
mov [di], al ; contents of combined string
inc di ; ready for next one - same as "stosb"
jmp first_part
second_part:
mov si, part2
; leave di alone - it points after copied "part1" in buffer
second_loop:
mov al, [si]
inc si
mov [di], al
inc di
cmp al, '$' ; this time we *do* want to copy the '$'
jne second_loop ; keep going until we find it
mov dx, whole ; !!!
mov ah, 9
int 21h
ret ; return to dos
part2 db "word$"
part1 db "Pass$"
section .bss ; uninitialized data
; reserve a place for whole password
whole resb 20h ; make sure it's big enough!!!
That doesn't take any user input, or compare strings, but is it one of the steps you're trying to do?
Best,
Frank
.
- References:
- simple 47 bits newbe ;_0
- From: Jean Pierre Daviau
- Re: simple 47 bits newbe ;_0
- From: Bx.C / x87asm
- Re: simple 47 bits newbe ;_0
- From: Jean Pierre Daviau
- Re: simple 47 bits newbe ;_0
- From: Frank Kotler
- Re: simple 47 bits newbe ;_0
- From: Herbert Kleebauer
- Re: simple 47 bits newbe ;_0
- From: Frank Kotler
- Re: simple 47 bits newbe ;_0
- From: Charles Crayne
- Re: simple 47 bits newbe ;_0
- From: Jean Pierre Daviau
- Re: simple 47 bits newbe ;_0
- From: Wolfgang Kern
- Re: simple 47 bits newbe ;_0
- From: Jean Pierre Daviau
- Re: simple 47 bits newbe ;_0
- From: Frank Kotler
- Re: simple 47 bits newbe ;_0
- From: Jean Pierre Daviau
- simple 47 bits newbe ;_0
- Prev by Date: Re: Deciimal to Hexa
- Next by Date: Re: Deciimal to Hexa
- Previous by thread: Re: simple 47 bits newbe ;_0
- Next by thread: Re: simple 47 bits newbe ;_0
- Index(es):
Relevant Pages
|