Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailemVyřešeno Assembler - jc nefunguje ako ma

Zdravim mam jeden velky problem v mojom kode, kde mam nalinkovanu proceduru s hl. programom kde mam menu. Obe maju zdielane procedury v include no v procedurach som pouzival jmp hl. menu ale akonahle som zlinkoval s externou procedurou ona hl. menu nepozna nakolko je iba v hlavnom subore. Preto som sa rozhodol upravit kod takto:

;PROCEDURA OTVORI SUBOR
FILE_OPEN PROC 
    PRINT newLine
    xor dx,dx
    mov ah,3dh                        ; DOS funkcion to open a file
    xor al,al                         ; clearing al register
    lea dx,filename                   ; set file name                          
    clc                               ; clear carry flag
    int 21h                           ; interrupt   
    jc  ERROR                         ; if a problem appears jump to ERROR
    mov handle,ax                     ; save file handle           
    ret
ERROR:                                  ; if problem appeared, info message will be thrown and procedure will end
    CALL CLRSCR
    PRINT err_file_open
    PRINT newLine
    ret            ;TU BOLO namiesto RET JMP HL.MENU
ENDP

Tuto proceduru pouzivam v procedure tuto:

FILE_PRINT PROC 
    CALL CLRSCR
    CALL FILE_OPEN
    jc ERROR3  
READ:
    mov ah,3fh                   ; reading from file
    mov bx,handle                ; handle is where my file is placed
    mov cx,1024                   ; reading 50 chars                                 
    lea dx,readBuff              ; moving begining of {at fist empty) string to dx
    int 21h                      ; interrupt  
    mov cx,ax                    ; number of the read chars is moved to cx
    xor si,si                    ; to be sure, the index will start at 0th position
    cmp ax,1024                   ; was 50 chars read?
    jnz LAST                     ; if less than 50 chars was read, I'm reaching end of file, last print is going to happen
CYCLE:  
    mov ah,02h                  ; DOS funkcion to print char
    mov dl,readBuff[si]         ; what is going to be print, si is pointer to the exact location in input_string 
    int 21h                     ; interrupt (now, the letter appears)
    inc si                      ; moving pointer further 
    loop CYCLE                     ; looping while cx is not 0, the value in cx is subtracting
    jmp READ                    ; when all 50 chars are already written, next 50 chars are going to be read
ERROR3:
    ret
LAST:                           ; LAST_PRINT does the same thing as GO, but after cx reaches 0, procedure ends
    mov ah,02h
    mov dl,readBuff[si]
    int 21h
    inc si  
    loop LAST
    PRINT newLine
    call FILE_CLOSE
    ret
ENDP

Tato procedura by sa mala pri zle otvorenom subore vratit a po jej ukonceni ma byt zavolane v hl. subore menu takze by to malo problem vyriesit no FILE_OPEN zaznamena chybu ale v druhej procedure JZ po zavolani FILE_OPEN neskoci. Kde je chyba? Dakujem za odpovede :)

Jsou zobrazeny jen nové odpovědi. Zobrazit všechny
Předmět Autor Datum
A spravne sa to robi tak ze funkcia nezasaghuje do nejakych globalnych premennych, ale vrati handle… nový
MM.. 22.03.2017 20:38
MM..
Diky moc si mi pomohol som nevedel ze taketo finty su paradne :) poslední
Parker 22.03.2017 22:21
Parker

A spravne sa to robi tak ze funkcia nezasaghuje do nejakych globalnych premennych, ale vrati handle v ax, a do nejakych premennych si to das az po navrate fcie. A fcia co otvara subor len otvara subor, a necarbe po obrazovke.
Potom to bude napr. takto

FILE_OPEN PROC 
    push dx
    mov ah,3dh                        ; DOS funkcion to open a file
    xor al,al                         ; clearing al register
    int 21h                           ; interrupt   
    pop dx
    ret                               ; vraciam buf CF alebo handle v AX
ENDP

pozn: push dx a pop dx sa da dosiahnut aj tak, ze sa do deklaracie fcie napise
FILE_OPEN PROC uses DX

hlavny program (tu riesim ze co bude na obrazovke, a ne kdesi vo file open) napr.

FILE_PRINT PROC
    CALL CLRSCR
    lea dx,filename
    CALL FILE_OPEN
    jc ERROR3
    mov handle, ax
...

P.S> v assembleri mozes principialne robit to iste co v C, parametre do funkcie posles bud v registri alebo v stacku, a navr. hodnotu v CF a (E)AX registri apod.
T.j. neco ako v C:
if(handle=FileOpen("nazov")) RobNeco(handle) else error();
bude v asm:
lea dx, nazov_str
call FileOpen
jc error
call RobNeco ;v AX uz mam handle, to moze byt rovno parameter tej funkcie...
jmp exit

Zpět do poradny Odpovědět na původní otázku Nahoru