flat assembler
Message board for the users of flat assembler.
Index
> DOS > cmp strings |
Author |
|
revolution 14 Jul 2008, 03:51
There appears to be nothing wrong with the code you posted there except that perhaps you want to use repe instead of rep. What is the specific problem you have? Can't compile? Compiles wrongly? Doesn't compare properly? Something else?
|
|||
14 Jul 2008, 03:51 |
|
abuashraf 17 Jul 2008, 23:34
Now I changed it to this ad it worked out:
Code: mov si,msg1 mov di,msg2 mov cx,6 rep cmpsb jne notequal but I still couldn't use LES LDS... |
|||
17 Jul 2008, 23:34 |
|
LocoDelAssembly 18 Jul 2008, 00:22
Could you post from the other code the part where you declare src and dest variables?
|
|||
18 Jul 2008, 00:22 |
|
revolution 18 Jul 2008, 00:30
Perhaps ES and DS are not properly restored after the cmpsb.
|
|||
18 Jul 2008, 00:30 |
|
abuashraf 19 Jul 2008, 00:35
LocoDelAssembly wrote: Could you post from the other code the part where you declare src and dest variables? Sure,here's the whole code: Code: org 100h jmp start str1 db 'first string',0 str2 db 'second string',0 wrong db 'mismatch$' okay db 'match$' start: lds si, str1 les di, str2 cld mov cx, 12 rep cmpsb jne @@mismatch @@match: mov dx,okay mov ah,09 int 21h int 20h @@mismatch: mov dx,wrong mov ah,09 int 21h int 20h fasm is giving me:invalid operand |
|||
19 Jul 2008, 00:35 |
|
LocoDelAssembly 19 Jul 2008, 01:55
Sure that MASM supports the instruction as you wrote it?
The problem is that LDS and family needs a far pointer stored in memory but you are passing an offset instead. Also note that normally you would use L*S only for run-time generated pointers, for global variables you would normally set the segment register by yourself. Here a working program that shows an example of when L*S could be used. Code: org $100 mov ah, $48 mov bx, (msg_end - msg + 15)/16 int $21 jc error mov word [pointer_var], 0 mov word [pointer_var+2], ax mov es, ax xor di, di mov si, msg mov cx, msg_end - msg rep movsb ; push [pointer_var] Not supported in earlier processors push word [pointer_var+2] push word [pointer_var] call some_proc_with_far_pointer_param exit: xor ax, ax int $16 int $20 some_proc_with_far_pointer_param: push bp mov bp, sp push ds lds dx, [bp+4] mov ah, $09 int $21 pop ds leave retn 4 error: mov ah, $09 mov dx, error_msg int $21 jmp exit error_msg db "Error allocating memory!$" msg db "Hello World! $" msg_end: pointer_var dd ? Very stupid example of course but shows when such instructions are useful. [edit]I forgot to tell, in the case of COM executables, at program start you are guarantied to have CS=DS=ES=SS[/edit] |
|||
19 Jul 2008, 01:55 |
|
revolution 19 Jul 2008, 02:12
LDS and LES must point to a two word structure that contain the segment and offset of your strings. Also you forgot to restore DS after you do the cmpsb. but note that you don't need to use LDS or LES since the strings can be accessed from the same segment. Try this:
Code: org 100h jmp start str1 db 'first string',0 str2 db 'second string',0 wrong db 'mismatch$' okay db 'match$' start: mov ax,cs mov ds,ax mov es,ax mov si, str1 mov di, str2 cld mov cx, 12 rep cmpsb jne @@mismatch @@match: mov dx,okay mov ah,09 int 21h int 20h @@mismatch: mov dx,wrong mov ah,09 int 21h int 20h |
|||
19 Jul 2008, 02:12 |
|
abuashraf 19 Jul 2008, 02:39
Thank you guys that was helpfull,but I have a couple of questions...
Quote: I forgot to tell, in the case of COM executables, at program start you are guarantied to have CS=DS=ES=SS why would I need to do that? and does this apply to .exe and .bin files? Thanx. |
|||
19 Jul 2008, 02:39 |
|
LocoDelAssembly 19 Jul 2008, 02:48
You have to do nothing I meant that DOS sets all the segment registers to the same value before giving control of the CPU to the COM program. This is not true for EXEs, but yet LDS and LES are not very helpful because you can address the global variables as revolution does.
|
|||
19 Jul 2008, 02:48 |
|
LocoDelAssembly 19 Jul 2008, 03:09
Just for the record here an example that uses both ways to get the far pointer of a global variable
Code: format MZ entry main:start stack $100 segment main start: lds dx, dword [cs:p_hello] ; Segment override because DS is undefined and CS points to the same segment where the string is stored mov ah,9 int 21h mov ax, main ; Redundant actually since the LDS above already set mov ds, ax ; DS to main segment mov dx, hello2 mov ah,9 int 21h xor ax, ax int $16 mov ax,4C00h int 21h p_hello dw hello, main hello db 'Hello world!', 13, 10, '$' hello2 db 'Hello again!', 13, 10, '$' |
|||
19 Jul 2008, 03:09 |
|
abuashraf 20 Jul 2008, 00:24
Thank you LocoDelAssembly
|
|||
20 Jul 2008, 00:24 |
|
Madis731 20 Jul 2008, 08:21
I was expecting some SSE4 implementation
|
|||
20 Jul 2008, 08:21 |
|
Matrix 05 Aug 2008, 02:50
|
|||
05 Aug 2008, 02:50 |
|
Madis731 05 Aug 2008, 06:40
Matrix wrote: http://board.flatassembler.net/topic.php?t=2633 Yeah, but why keep things simple, when you can make them complicated |
|||
05 Aug 2008, 06:40 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.