Welcome back, Guest!
Register
Forgot your Password?

Hello, Guest! Welcome to Symbianize Forum.

Most of our features and services are available only to our members. So we encourage you to login or join us by registering a new account. Registration is free, fast, and simple. You only need to provide a valid email address so we can minimize spammers. As a Symbianize member you'll have the following privileges:

All that and more, so what are you waiting for, join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Results 1 to 7 of 7
  1. #1

    Help [HELP] Explain a Assembly code; Palindrome

    Hello po, pa'explain naman po ung code na to, tungkol po ito sa Plaindrome (ung word na khit baliktarin mo ung basa pareho pa din ex: abba). At Assembly language po ito gawa sa codes for TASM(Turbo Assembler). kelangan ko lang po mai-explain ito. di po kasi ako pamilyar sa Assembly language. ano po ba ang functions at ibig sabihin ng bawat line? Please po mga ka-symb! sana matulungan nyo po ako. Thanks in advanced.





    DOSSEG
    .MODEL SMALL
    .STACK 100H

    .DATA
    M1 DB "ENTER STRING TO BE CHECKED:",0AH,0DH,'$'
    M2 DB "STRING IS PALLINDROME",0AH,0DH,'$'
    M3 DB "STRING IS NOT PALLINDROME",0AH,0DH,'$'
    MAXCHAR DB 50
    ACTUAL DB ?
    BUFFER DB 50 DUP(?)

    .CODE
    MAIN PROC
    MOV AX,@DATA
    MOV DS,AX

    MOV AH,09H
    MOV DX,OFFSET M1
    INT 21H
    MOV AH,0AH
    MOV DX,OFFSET MAXCHAR
    INT 21H

    MOV CH,00H
    MOV CL,ACTUAL
    MOV SI,OFFSET BUFFER
    MOV BH,00H
    AG: MOV BL,[SI]
    PUSH BX
    INC SI
    LOOP AG

    MOV CH,00H
    MOV CL,ACTUAL
    MOV SI,OFFSET BUFFER
    GO: POP BX
    CMP [SI],BL
    JNE NO
    INC SI
    LOOP GO

    MOV AH,09H
    MOV DX,OFFSET M2
    INT 21H
    JMP EN

    NO: MOV AH,09H
    MOV DX,OFFSET M3
    INT 21H

    EN: MOV AH,4CH
    INT 21H
    MAIN ENDP
    END MAIN

  2. #2

    Default Re: [HELP] Explain a Assembly code; Palindrome

    ang palindrome kahit baliktadin mo ang word
    pariho pa din ang lalabas...
    toot -> is palindrome

  3. #3

    Default Re: [HELP] Explain a Assembly code; Palindrome

    try this XD

    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>

    int is_palindrome(char*);
    void copy_string(char*, char*);
    void reverse_string(char*);
    int string_length(char*);
    int compare_string(char*, char*);

    main()
    {
    char string[100];
    int result;

    printf("Enter a string\n");
    gets(string);

    result = is_palindrome(string);

    if ( result == 1 )
    {
    printf("\"%s\" is a palindrome string.\n", string);
    getch();}
    else
    {
    printf("\"%s\" is not a palindrome string.\n", string);
    getch();
    }
    return 0;
    }

    int is_palindrome(char *string)
    {
    int check, length;
    char *reverse;

    length = string_length(string);
    reverse = (char*)malloc(length+1);

    copy_string(reverse, string);
    reverse_string(reverse);

    check = compare_string(string, reverse);

    free(reverse);

    if ( check == 0 )
    return 1;
    else
    return 0;
    }

    int string_length(char *string)
    {
    int length = 0;

    while(*string)
    {
    length++;
    string++;
    }

    return length;
    }

    void copy_string(char *target, char *source)
    {
    while(*source)
    {
    *target = *source;
    source++;
    target++;
    }
    *target = '\0';
    }

    void reverse_string(char *string)
    {
    int length, c;
    char *begin, *end, temp;

    length = string_length(string);

    begin = string;
    end = string;

    for ( c = 0 ; c < ( length - 1 ) ; c++ )
    end++;

    for ( c = 0 ; c < length/2 ; c++ )
    {
    temp = *end;
    *end = *begin;
    *begin = temp;

    begin++;
    end--;
    }
    }

    int compare_string(char *first, char *second)
    {
    while(*first==*second)
    {
    if ( *first == '\0' || *second == '\0' )
    break;

    first++;
    second++;
    }
    if( *first == '\0' && *second == '\0' )
    return 0;
    else

    return -1;
    }

  4. #4

    Default Re: [HELP] Explain a Assembly code; Palindrome

    Quote Originally Posted by jorizh09 [Link available to registered users only. Click here to register.]
    Hello po, pa'explain naman po ung code na to, tungkol po ito sa Plaindrome (ung word na khit baliktarin mo ung basa pareho pa din ex: abba). At Assembly language po ito gawa sa codes for TASM(Turbo Assembler). kelangan ko lang po mai-explain ito. di po kasi ako pamilyar sa Assembly language. ano po ba ang functions at ibig sabihin ng bawat line? Please po mga ka-symb! sana matulungan nyo po ako. Thanks in advanced.





    DOSSEG
    .MODEL SMALL
    .STACK 100H

    .DATA
    M1 DB "ENTER STRING TO BE CHECKED:",0AH,0DH,'$'
    M2 DB "STRING IS PALLINDROME",0AH,0DH,'$'
    M3 DB "STRING IS NOT PALLINDROME",0AH,0DH,'$'
    MAXCHAR DB 50
    ACTUAL DB ?
    BUFFER DB 50 DUP(?)

    .CODE
    MAIN PROC
    MOV AX,@DATA
    MOV DS,AX

    MOV AH,09H
    MOV DX,OFFSET M1
    INT 21H
    MOV AH,0AH
    MOV DX,OFFSET MAXCHAR
    INT 21H

    MOV CH,00H
    MOV CL,ACTUAL
    MOV SI,OFFSET BUFFER
    MOV BH,00H
    AG: MOV BL,[SI]
    PUSH BX
    INC SI
    LOOP AG

    MOV CH,00H
    MOV CL,ACTUAL
    MOV SI,OFFSET BUFFER
    GO: POP BX
    CMP [SI],BL
    JNE NO
    INC SI
    LOOP GO

    MOV AH,09H
    MOV DX,OFFSET M2
    INT 21H
    JMP EN

    NO: MOV AH,09H
    MOV DX,OFFSET M3
    INT 21H

    EN: MOV AH,4CH
    INT 21H
    MAIN ENDP
    END MAIN
    parang me mali nung nirun ko.. yung @data

  5. #5

    Default Re: [HELP] Explain a Assembly code; Palindrome

    Quote Originally Posted by alreykjohn [Link available to registered users only. Click here to register.]
    parang me mali nung nirun ko.. yung @data
    Pafs, that is actually correct asm code kasi di pwedeng direct mov DS, @data so kailangan mo muna ng mov ax, @data then mov ds,ax.

  6. #6

    Default Re: [HELP] Explain a Assembly code; Palindrome

    alright... prob with my 64bit

  7. #7

    Default Re: [HELP] Explain a Assembly code; Palindrome

    NOTE: lines starting with ';' (semi-colon) are comments

    DOSSEG
    .MODEL SMALL
    .STACK 100H

    .DATA
    M1 DB "ENTER STRING TO BE CHECKED:",0AH,0DH,'$' ; string to be printed before receiving the input
    M2 DB "STRING IS PALLINDROME",0AH,0DH,'$' ; string to be printed if input is palindrome
    M3 DB "STRING IS NOT PALLINDROME",0AH,0DH,'$' ;string to be printed if input is not palindrome

    ;;;;
    MAXCHAR DB 50
    ACTUAL DB ?
    BUFFER DB 50 DUP(?)
    ;;;; isang grupo tong last three lines, strict ang order nito
    ;;;; maxchar means the maximum character (minus 1 lagi kasi yung last character ay '0Dh' o yung ascii ng 'enter' key)
    ;;;; usually, parehas ang value ng maxchar at buffer, ang idea dyan ay magset ng maximum character input, mag-add ng one
    ;;;; sa max character input na naiset, tapos yun ang ilalagay sa maxchar at buffer, so dito ang maximum na pwedeng makuha ay 50 - 1 = 49 valid alpabetic / numeric characters
    ;;;; yung sa 'ACTUAL' namn, dyan pumapasok yung actual length ng string na nai-input, example: 'Joshua', tapos 'enter'
    ;;;; yung input na 'Joshua' ay 6 characters in length, plus yung 'enter' character, so 7 ang length
    ;;;; sa BUFFER DB 50 dup(?) : '?' means an uninitialized variable, walang value. ang function ng DUP(?) ay shortcut para itype ang 50 '?'
    ;;;; example storage db 4 dup('X') yields 'XXXX', 4 letters ng X

    .CODE
    MAIN PROC ; PROC means procedures (prang method sa ibang language kung tama ako)

    ;;;;
    MOV AX,@DATA
    MOV DS,AX
    ;;;; hindi ako pamilyar sa codes na to, pero ang idea dito eh i-load ang mga variables na nasa data segment
    ;;;; hindi kasi ganito yung way ko sa pagdedefine ng variables nung nagcocode kami ng simple assembly

    ;;;;
    MOV AH, 09h
    MOV DX,OFFSET M1
    INT 21H
    ;;;; last three lines : INT 21h, service 09h ->> interrupt service yang ibig sabihin ng INT. ang function ng interrupt 21 service 09h ay magprint
    ;;;; ng string. ang string na ipprint ay dapat nagtatapos sa '$', string terminator yung '$', ibig sabihin hihinto sa print pag nakita yung '$'
    ;;;; nilalagay sa DX register yung address ng string na ipprint, in this case ginamit yung 'MOV DX, OFFSET M1', pwede ring gamitin yung
    ;;;; LEA DX, M1' or Load Effective Address
    ;;;; tinatawag yung 'INT 21h' pag nka-set na yung 'AH' o yung type ng service, tska yung 'DX' o yung string na ipprint

    ;;;;
    MOV AH,0AH
    MOV DX,OFFSET MAXCHAR
    INT 21H
    ;;;; last three lines: 'INT 21h, service 0AH', ang function namn ng service na to ay humingi ng multicharacter input galing sa user
    ;;;; konektado to dun sa 3 lines sa taas na may 'MAXCHAR', 'ACTUAL', tska 'BUFFER'
    ;;;; sa DX nilalagay yung address ng maximum characters
    ;;;; after matawag ang int 21h service 0ah, manghihingi ng input ang system, pressing 'enter' key means you're done typing your input
    ;;;; pagkapindot ng enter, ilalagay ng system yung length ng na-input sa 'ACTUAL' variable, tapos yung mismong characters na nai-type ay
    ;;;; mapupunta sa 'BUFFER'

    ;;;;
    MOV CH,00H
    MOV CL,ACTUAL
    MOV SI,OFFSET BUFFER
    MOV BH,00H
    ;;;; registers have two parts : the lower part (yung may L) and the higher part (H), CX = CH and CL = CX
    ;;;; CX register : cx register is used when doing loops, example : pag 3 ang laman ng cx, pwede kang mkapagloop 3 times
    ;;;; nilagyan niya ng 00H yung CH, tapos nilagay niya yung laman ng ACTUAL sa CL, example : CH = 00H, input ko ay "Joshua" (plus 0Dh, length is 7)
    ;;;; so CX = CH + CL = 00H + 07H = 0007H

    ;;;;
    AG: MOV BL,[SI]
    PUSH BX
    INC SI
    LOOP AG
    ;;;; dito inimplement yung loop, as you can see the 'LOOP' keyword

    ;;;; yan muna sa ngayon, may lakad pa kasi ako, itutuloy ko paguwi ko mamaya, hehe


    MOV CH,00H
    MOV CL,ACTUAL
    MOV SI,OFFSET BUFFER
    GO: POP BX
    CMP [SI],BL
    JNE NO
    INC SI
    LOOP GO

    MOV AH,09H
    MOV DX,OFFSET M2
    INT 21H
    JMP EN

    NO: MOV AH,09H
    MOV DX,OFFSET M3
    INT 21H

    EN: MOV AH,4CH
    INT 21H
    MAIN ENDP
    END MAIN
    Last edited by thor007; 10th Apr 2013 at 09:15.

Posting Permissions

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