CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: i tried(((

  1. #1
    Join Date
    Apr 2009
    Posts
    19

    i tried(((

    --------------------------------------------------------------------------------

    i did as u told me and i have two errors
    **Error** zz.ASM(1) Unknown character
    **Fatal** zz.ASM(76) Unexpected end of file encountered.
    this is d new code:
    CLEAR MACRO COLOR ;Î÷èñòê* ýêð*** öâåòîì
    MOV AX, 0600H ;Ïðîêðóòê* âñåãî ýêð***
    MOV BH, COLOR
    XOR CX, CX
    MOV DX, 184FH
    INT 10H
    ENDM

    TEXTOUT MACRO TEXT ;Âûâîä òåêñò* ÷åðåç ôó*êöèþ 9 ïðåðûâ**èÿ

    21H
    MOV AH, 09
    LEA DX, TEXT
    INT 21H
    ENDM

    TEXTIN MACRO BUF ;Ââîä òåêñò* ÷åðåç
    MOV AH, 0AH
    LEA DX, BUF
    INT 21H
    ENDM

    StackS SEGMENT PARA STACK 'STACK'
    DW 32 DUP(?)
    StackS ENDS


    MAX_TEXT EQU 80
    DATA SEGMENT PARA PUBLIC 'DATA'
    MESS1 DB 0AH,0DH,"Ââåäèòå ñòðîêó: $"
    MESS2 DB 0AH,0DH,"Â ì*ëå*üêèõ áóêâ: $"


    BUF1 DB MAX_TEXT
    QNT1 DB 0
    TEXT1 DB MAX_TEXT DUP(?)


    DATA ENDS

    CODE SEGMENT PARA PUBLIC 'CODE'
    ASSUME CS:CODE, DSATA, SS:StackS

    START: MOV AX, DATA ; ç*ãðóçèòü â DS
    MOV DS, AX ;ñåëåêòîð ñåãìå*ò* ä***ûõ
    MOV ES, AX
    CLEAR 30
    TEXTOUT MESS1
    TEXTIN BUF1
    TEXTOUT MESS2 ; output the message "output: "

    XOR CH, CH ;Îáíóëåíèå ñòàðøåãî áàéòà ñ÷åò÷èêà
    MOV CL, QNT1 ;Çàãðóçêà êîëè÷åñòâà ñèìâîëîâ â ñòðîêå
    LEA SI, TEXT1 ;Àäðåñ îñíîâíîé ñòðîêè â èñòî÷íèê
    CLD

    print_upper: lodsb ; Get next char in str. *
    cmp al, "a" ; if < 'a', just print it
    jb print_it
    cmp al, "z" ; if > 'z' just print it
    ja print_it
    sub al, 20h ; if lower case a - z, make it upper
    print_it:
    call putc ; display the letter
    loop print_upper

    mov ax, 4c00h
    int 21h ; return to ms-dos

    putc: ; display character in dl
    mov dl,al
    mov ah, 2h
    int 21h
    ret

    CODE ENDS
    END START

    and cn u explain to me how to count d lines so i cn trace d errors

  2. #2
    Join Date
    Apr 2003
    Posts
    1,755

    Re: i tried(((

    Based on the non-english texts and comments you have, I tried to save the file with UNICODE encoding then compiled it, and I got the "Unexpected end of file encountered" The "unknown character" could be due to the language id you are using. To fix it, save the file using ANSI or UTF-8 encoding.

    I'm using Notepad2. It has line indicator so you don't need to count the number of lines.

    Hope it will work for you

  3. #3
    Join Date
    Apr 2009
    Posts
    19

    Re: i tried(((

    thanks so much its ok.i have so many things to learn in assembly language and i rily appreciate ur help.
    but i still got more things.
    i showed the fist program i did that is the one that counts the number of occurences of a character in a string to my teacher and he says it is correct but i should write it in a diferent way.he referred to the REPNE SCASB line and said i shud write it in a different way.he also said i shud write the program in such a way that i dnt have to input with the keyboard.meaning the program is jud=st gonna run itself.
    here is d code:
    CLEAR MACRO COLOR
    MOV AX, 0600H
    MOV BH, COLOR
    XOR CX, CX
    MOV DX, 184FH
    INT 10H
    ENDM

    TEXTOUT MACRO TEXT ;string output using the function 21H
    MOV AH, 09
    LEA DX, TEXT
    INT 21H
    ENDM

    TEXTIN MACRO BUF ;string input
    MOV AH, 0AH
    LEA DX, BUF
    INT 21H
    ENDM

    StackS SEGMENT PARA STACK 'STACK'
    DW 32 DUP(?)
    StackS ENDS


    MAX_TEXT EQU 80
    DATA SEGMENT PARA PUBLIC 'DATA'
    MESS1 DB 0AH,0DH,"input string: $"
    MESS2 DB 0AH,0DH,"input letter: $"
    MESSNOT DB 0AH,0DH,"letter not found.$"
    MESSYES DB 0AH,0DH,"it contains $ "

    BUF1 DB MAX_TEXT
    QNT1 DB 0
    TEXT1 DB MAX_TEXT DUP(?)

    DATA ENDS

    CODE SEGMENT PARA PUBLIC 'CODE'
    ASSUME CS:CODE, DSATA, SS:StackS

    START: MOV AX, DATA ;load into DS
    MOV DS, AX ;selects the given segment
    MOV ES, AX

    CLEAR 30
    TEXTOUT MESS1
    TEXTIN BUF1
    TEXTOUT MESS2
    MOV AH,1
    INT 21H

    XOR CH, CH ;clears upper bite
    MOV CL, QNT1 ;loads the number of symbols into the substring
    JCXZ NOTFOUND ;empty string is a part of string
    LEA DI, TEXT1 ;address of the substring in source input
    XOR BX,BX
    CLD ;sets the flag in the direction of ascending order

    NEXT:
    *REPNE SCASB ; continuously scan until a match is found or CX is 0
    *JNE CONTINUE ; if no match, goto show the result
    *ADD BX,1 ; if match, increment our count
    *JCXZ CONTINUE ; if nothing more to process, goto show the result
    *JMP NEXT ; otherwise, continue with our loop

    *CONTINUE:

    *CMP BX,0 ;compare string
    *JE NOTFOUND

    PUSH BX ; save our count into the stack
    TEXTOUT MESSYES
    POP AX ; put the count (from the stack) to AX

    ; PRINT the value of AX

    mov bx, sp
    divide_by10:
    xor dx, dx
    mov cx, 10
    div cx
    push dx
    or ax, ax
    jnz divide_by10
    print_result:
    mov ah, 2
    pop dx
    add dl, '0'
    int 21h
    cmp sp, bx
    jne print_result

    JMP EXIT

    NOTFOUND:
    TEXTOUT MESSNOT

    EXIT: XOR AL, AL
    MOV AH, 4CH
    INT 21H
    CODE ENDS
    END START
    he askd me to rewrite the parts i marked with asteriks in the program.

    secondly he askd me to write another program that puts a frame around a string wen i input with the keyboard.
    example: hello
    wud appear on the screen as *******
    *hello *
    ***** *
    the size of the frame changes with the lenght of the word inputed.
    thks))

  4. #4
    Join Date
    Apr 2003
    Posts
    1,755

    Re: i tried(((

    Did he tell you why REPNE SCASB should not be used? Is there something wrong with it? Anyway you can check the input 1 by 1 incrementing the pointer in every iteration
    Code:
    XOR CH, CH
    MOV CL, QNT1
    JCXZ NOTFOUND
    LEA DI, TEXT1
    XOR BX,BX
    CLD
    
    COMPARE_IT:
      cmp al, [di]      ; compare AL with the byte in [di]
      jne NEXT_CHAR     ; if NOT match, goto next character
      inc bx            ; if match, increment our count
    NEXT_CHAR:
      inc di            ; increment our pointer
      loop COMPARE_IT   ; loop until CX == 0
      
    ;NEXT:
    ;REPNE SCASB         ; continuously scan until a match is found or CX is 0
    ;JNE CONTINUE        ; if no match, goto show the result
    ;ADD BX,1            ; if match, increment our count
    ;JCXZ CONTINUE       ; if nothing more to process, goto show the result
    ;JMP NEXT            ; otherwise, continue with our loop
    
    ;CONTINUE:
    
    CMP BX,0
    JE NOTFOUND
    If you want the string input to be hard coded, you can preset your QNT1 and TEXT1 and remove the TEXTIN. For example the string is "testing"
    Code:
    QNT1 DB 7
    TEXT1 DB "testing"
    This way you don't need to change the way you process the string.

    For printing the string with '*' frame. Since you can get the length of the input string, just output '*' for len + 2 (1 in front and 1 at the back of the input) in the first line. For the second line, output '*' and then the string and finally the '*' at the back. The 3rd line would be the same as the first line.

  5. #5
    Join Date
    Apr 2009
    Posts
    19

    Re: i tried(((

    thanks so much for ur help.i worked on inputing d string hard coded and it was working well.but wen i tired on working on the input of the string to be compared als to b hard coded,its not working correctly.i need to write d program in a way such dat everything is hard coded.this is what i have written can u tell me wat isnt right cos it keeps showing me letter not found after i press the enter key wen i run he program.



    CLEAR MACRO COLOR
    MOV AX, 0600H
    MOV BH, COLOR
    XOR CX, CX
    MOV DX, 184FH
    INT 10H
    ENDM

    TEXTOUT MACRO TEXT
    MOV AH, 09
    LEA DX, TEXT
    INT 21H
    ENDM

    TEXTIN MACRO BUF
    MOV AH, 0AH
    LEA DX, BUF
    INT 21H
    ENDM

    StackS SEGMENT PARA STACK 'STACK'
    DW 32 DUP(?)
    StackS ENDS



    DATA SEGMENT PARA PUBLIC 'DATA'


    MESSNOT DB 0AH,0DH,"letter not found.$"
    MESSYES DB 0AH,0DH,"it contains $"

    BUF1 DB "x"
    QNT1 DB 7
    TEXT1 DB "tsdfaxc"

    DATA ENDS

    CODE SEGMENT PARA PUBLIC 'CODE'
    ASSUME CS:CODE, DSATA, SS:StackS

    START: MOV AX, DATA
    MOV DS, AX
    MOV ES, AX

    CLEAR 30
    TEXTIN BUF1
    MOV AH,1
    INT 21H

    XOR CH, CH
    MOV CL, QNT1
    JCXZ NOTFOUND
    LEA DI, TEXT1
    XOR BX,BX
    CLD

    COMPARE_IT:
    cmp al, [di] ; compare AL with the byte in [di]
    jne NEXT_CHAR ; if NOT match, goto next character
    inc bx ; if match, increment our count
    NEXT_CHAR:
    inc di ; increment our pointer
    loop COMPARE_IT

    CMP BX,0
    JE NOTFOUND

    PUSH BX
    TEXTOUT MESSYES
    POP AX


    mov bx, sp
    divide_by10:
    xor dx, dx
    mov cx, 10
    div cx
    push dx
    or ax, ax
    jnz divide_by10
    print_result:
    mov ah, 2
    pop dx
    add dl, '0'
    int 21h
    cmp sp, bx
    jne print_result

    JMP EXIT

    NOTFOUND:
    TEXTOUT MESSNOT

    EXIT: XOR AL, AL
    MOV AH, 4CH
    INT 21H
    CODE ENDS
    END START

    i also need help in the second question i asked about printing out a string with a framed(*).
    example:hello
    on the screen ******
    *hello*
    ******
    the size of the frame increases wtih the sizze of the string.i have bn tying to write the program but i cnt figure anything out plas i need help

  6. #6
    Join Date
    Apr 2003
    Posts
    1,755

    Re: i tried(((

    You get the "letter not found" error because you are still using the TEXTIN macro w/c will overwrite the content of your BUF1. You have to remove the TEXTIN in your code.

    To hardcode the character to compare you have to remove the interrupt 21 function 01 and hardcode the character in AL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured