0

I am trying to implement an algorithm in assembly x86 using tasm and tlink.

when I run it in dosbox with the commands: tasm /zi base tlink /v base I get the following error: "Error when compiling - Fatal: 32-bit encounterd in module BASE.ASM"

I figured out that the problem is in "condtwo" but I cant find the bug.

MODEL small
.386
STACK 100h
DATASEG
; --------------------------
    string db "aaabbbaaabbbaaa"
    break db "$"
    w dd 4095
    maxl dd 31
    maxm dd 0
    offst dd 0
    p dd 7
    stringsize dd 0
    la db 0
    lb db 0
    k dd 0
    inword dd 0h
    arr dd ?

; --------------------------
CODESEG
start:
    mov eax, @data
    mov ds, eax
; --------------------------
    call strlen
    call maxmatch
; --------------------------

strlen proc
    xor eax, eax
    xor cx, cx
    mov si, offset string
    stringlen:
        mov ah, [byte ptr si]
        inc al
        inc si
        cmp ah, [break]
    jne stringlen
    dec al
    mov ah, 0
    mov [stringsize], eax
    ret
endp strlen

maxmatch proc
    xor edx, edx
    minpw:
        mov eax, [p]
        inc eax
        mov ebx, [w]
        cmp eax, ebx
    jbe inip
    ja iniw
    inip:
        mov ecx, eax
        dec ecx
        jmp mainloop
    iniw:
    mov ecx, ebx
    dec ecx
    mainloop:
        inc edx
        mov [k], 0
        mov eax, [stringsize]
        sub eax, [p]
        cmp eax, [maxl]
        jbe ininp
        ja iniml
        ininp:
            mov ebx, eax
            jmp condtwo
        iniml:
            mov ebx, [maxl]
            jmp condtwo
        condtwo:
            mov esi, offset string
            add si, [word ptr p]
            mov eax, [dword ptr si]
            sub si, [word ptr edx]
            cmp [dword ptr si], eax
            je loopbody
        loopbody:
            inc [k]
            cmp [k], ebx
        jb condtwo
        mov eax, [k]
        cmp [maxm], eax
        jb consuccess
        consuccess:
            mov [maxm], eax
            mov offst, edx
        loop mainloop

endp maxmatch

exit:
    mov ax, 4c00h
    int 21h
END start
Nimrod Naim
  • 125
  • 8
  • 1
    Just a guess, but try `mov si, offset string`. PS: you seem to be confused about 32 bit usage. – Jester Jun 04 '18 at 19:20
  • Does TASM really accept `[dword ptr si]` instead of `dword ptr [si]`? Are you using `mov esi, offset string` and `xor eax,eax` for higher performance on modern CPUs, e.g. to avoid false dependencies vs. writing only the low 16 bits of a 32-bit register? [Why doesn't GCC use partial registers?](https://stackoverflow.com/q/41573502) – Peter Cordes Jun 05 '18 at 00:29
  • tlink doesn't like `mov esi, offset string`. You can force the linking with the switch /3: `tlink /v /3 base`. There a lot of other issues with your code, e.g. nested functions. Don't use 32-bit registers in a 16-bit program, if you don't need them urgently! – rkhb Jun 05 '18 at 05:26

0 Answers0