Thread: Just finished assembly assignment

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Just finished assembly assignment

    I was wondering if anyone would like to comment on my assembly assignment.
    I have finished it, and wanted ideas on optimising.
    I have already submitted it to my teacher, but would love to know any good ideas on how to make it better.
    Thanks.
    x

    H1 Machine-Level
    Simulator Version 5.0 Copyright (c) 2005 A. J. Dos Reis

    Code:
    ;DISCRIPTION:
    ;(1) Reads user inputed string Max 20 Characters
    ;(2) Analyses it to see if a palindrome was entered.
     
    ;////////////////////////////////
    ;/////////////main///////////////
    ;////////////////////////////////
    IDeclareRoShamBo: 
    call acquireString ;call to acquireString module 
    call stringCount ;call to stringCount module
    call palindrome ;call to palendrome module
     
    error: ;early exit for pelendrome failure
    halt ;end of program
    Done: 
     
    ;////////////////////////////////
    ;/////function acquireString/////
    ;////////////////////////////////
    acquireString:
    ldc '\n' ;load newline into ac
    aout ;print newline to screen
    ldc msg1 ;load message into ac
    sout ;print message
    ldc inbuf ;load address of buffer
    sin ;read in string
    ldc '\n' ;load newline into ac 
    aout ;print newline to screen 
    ldc inbuf ;load address of buffer 
    sout ;print newline to screen
    ret
    ;////////////////////////////////
    ;/////function stringCount///////
    ;////////////////////////////////
    stringCount:
    loop1: ;loop label
    ld count ;load counter
    add @1 ;add 1 to counter
    st count ;store counter
    ldc inbuf ;load address of buffer
    add count ;increment address 
    ldi ;load value stored at address
    jnz loop1 ;loop if not zero
     
    ret
    ;/////////////////////////////////
    ;/////function palindrom//////////
    ;/////////////////////////////////
    palindrome:
    ld count ;load count
    sub @1 ;subtract 1 from count
    st bindex ;store as back index
     
    loop3: ;analysis loop
    ldc inbuf ;load address of inbuf
    add bindex ;add backward decrement to address
    ldi ;load value pointed to
    st testValue1 ;store value in test variable
     
    ldc inbuf ;load address of inbuf
    add findex ;add forward increment to address
    ldi ;load value pointed to
    st testValue2 ;store value in test variable
    sub testValue1 ;subtract testValue1 from testValue2
    st testResult ;store result
     
    jnz notPalin ;if value is 0 execute notPalin 
     
    call crossIncr ;call crossIncr to move pointer addresses
    ld bindex ;load bindex to determine more analysis
    jzop loop3 ;loop if analysis is not complete
    call isPalindrome ;call function isPalindrome
    ret
    ;////////////////////////////////
    ;///Function crossIncr///////////
    ;////////////////////////////////	
    crossIncr:
    ld findex ;load findex to ac
    add @1 ;increment findex
    st findex ;store findex
    ld bindex ;load bindex to ac
    sub @1 ;decrement bindex
    st bindex ;store bindex
    ret
    ;////////////////////////////////
    ;///Function notPalin////////////
    ;////////////////////////////////	
    notPalin:
    ldc '\n' ;load newline into ac
    aout ;print newline to screen
    ldc msg2 ;load message into ac
    sout ;print message
    ldc '\n' ;load newline into ac 
    aout ;print newline to screen
    ja error
    ;////////////////////////////////
    ;///Function isPalindrome////////
    ;////////////////////////////////	
    isPalindrome:
    ldc '\n' ;load newline into ac
    aout ;print newline to screen
    ldc msg3 ;load message into ac
    sout ;print message
    ldc '\n' ;load newline into ac 
    aout ;print newline to screen
    ret
    ;////////////////////////////////
    ;//////////data area/////////////
    ;////////////////////////////////
    inbuf: dw 20 dup 0
    bindex: dw 0
    findex: dw 0
    @1: dw 1
    count: dw 0
    testValue1: dw 0
    testValue2: dw 0
    testResult: dw 0
    msg1: dw "Enter String: "
    msg2: dw "String is not palindrome"
    msg3: dw "String is palindrome"
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Moved to a better forum.

    > ldc '\n' ;load newline into ac
    These kinds of comments don't add anything to the understanding IMO
    Sure they tell you what is happening, but anyone awake could probably figure that out.

    ;////////////////////////////////
    ;/////function acquireString/////
    ;////////////////////////////////
    ;Prompts user with a message and returns their input in inbuf

    A decent functional description of what each function does goes a long way to removing lots of tedious comments.
    Though for some bizarre reason, some tutors seem to like repetetive boredom as some indication of knowledge

    Also, a blank line or two between functions wouldn't be a bad idea either.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    What platform is this for?

  4. #4
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    I'm very curious too, it looks kind of like a cross-bread of registerless vax and x86.
    Is the accumulator all you have?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Says it all really

    H1 Machine-Level
    Simulator Version 5.0 Copyright (c) 2005 A. J. Dos Reis

    It's not a real machine, just a pretend one
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Though for some bizarre reason, some tutors seem to like repetetive boredom as some indication of knowledge
    ;0) that is pretty funny.
    thanks for the input on the descriptions and comments. I will make some modifications asap.

    Salem is correct. This is a similator. We are not going to start working on real assemblers until the next couple of weeks.

    other then the poor documentation, can anyone see a way to streamline it more?
    i want to see if i can make this program as small and efficient as possible.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well you could store all the '\n' characters inside the string constants.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  3. Review my finished assignment
    By damonbrinkley in forum C Programming
    Replies: 11
    Last Post: 06-24-2003, 07:15 AM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM