PDA

View Full Version : assembly help



dicecca112
10-19-2006, 11:03 AM
I need some help with an assembly program. Its suppose to decode 4 lines of text 1x44 characters long by subtracting three from the hex representation of the character and then write over it, giving us the final message, but it doesn't do that. It rights the hex characters in sequence starting from 00 and so on.

I've attached the folder as well if anyone wants to try running it




INCLUDE Irvine32.inc

.data



mycode byte "Li#|rx#fdq#uhdg#wklv#phvvdjh#|rx#kdyh#vroyhg" ;text to decode
byte "wkh#sx}}oh#ehfdxvh#rqo|#wkhq#zloo#|rx#vhh#d#"
byte "phvvdjh#wkdw#pdnjv#dq|#vruw#ri#vhqvh1##Li###"
byte "|rx#jrw#wklv#idu#frqjudwxodwlrqv$$$$$$$$$$$$"

mycodelen = ($ - mycode) ;determines the length of the code
myrows = mycodelen / LENGTHOF mycode ;determines the number of rows
mycols = LENGTHOF mycode ;determines the number of columns
currentcol byte ? ;variable to hold the currentcol
currentrow byte ? ;variable to hold the currentrow
countsave dword ? ;variable to hold the counter from ecx
delayvar sword ? ;variable to hold the delay number for procedure delay
val3 = 3 ;variable to subtract 3

.code
main proc

;set up first loop to write encode text in 4X44 block

mov esi, OFFSET mycode
mov ecx, myrows ;put the number of rows in ecx
mov currentrow, 0 ;set the currentrow number to 0

OUTERLOOP1: ;start of outerloop
mov countsave, ecx ;move the value of ecx to countsave
mov ecx, mycols ;set ecx to the number of columns
mov currentcol, 0 ;set the currentcol to 0

INNERLOOP1: ;start of innerloop
mov dh, currentrow ;set the x variable of gotoxy to currentrow
mov dl, currentcol ;set the y variable of gotoxy to currentcol
call Gotoxy ;call gotoxy
mov al, [esi] ;mov the address of esi into al
call writechar ;call writechar
inc BYTE PTR [esi] ;increase the address of ESI by one
inc currentcol ;increase the curretcol
loop INNERLOOP1 ;end the loop
mov ecx, countsave ;move countsave back into ecx to restore later
inc currentrow ;increase current row
loop OUTERLOOP1 ;end the loop

mov delayvar, 1000 ;call the delay function
call Delay

;set up second loop to write decode text in a 4X44 block

mov esi, OFFSET mycode
mov ecx, myrows ;put the number of rows in ecx
mov currentrow, 0 ;set the currentrow number to 0

OUTERLOOP2: ;start of loop
mov countsave, ecx ;move value of ecx back into countsave
mov ecx, mycols ;move value of ecx into mycols
mov currentcol, 0 ;set currentcol to 0

INNERLOOP2: ;start loop
mov dh, currentrow ;set the x variable of gotoxy to currentrow
mov dl, currentcol ;set the y variable of gotoxy to currentcol
call gotoxy ;call gotoxy
mov al, [esi] ;mov the address of esi into al
sub al, val3 ;subtract three for al

call writechar ;call writechar
inc BYTE PTR [esi] ;increase the address of esi
inc currentcol ;increase the value of currentcol
mov delayvar, 200 ;call delay
call Delay

loop INNERLOOP2 ;end of loop

loop OUTERLOOP2 ;end of loop
call Crlf ;write end of line sequence

exit ;end of program
main ENDP

END main

BlueBiker
10-19-2006, 06:49 PM
(I'm assuming that any program setup has already been performed by the loader at the time main is entered, such as stack & segment register & flags initialization.)

You're most of the way there. The first thing that jumps out at me is the inc BYTE PTR [esi] which doesn't do what you want. It increments the byte in memory that ESI points to, but what you really want is a simple inc esi to increment the pointer itself.

The next thing is that there are two instructions missing between loop INNERLOOP2 and loop OUTERLOOP2 that should've been copied from the loops above.

Just a suggestion, don't get too enamored of using ECX and the LOOP instruction for all of your loops. Often it's simpler and faster to keep different counters in different registers (or leave them in memory locations) and just use DEC and JNZ to accomplish the loops.

dicecca112
10-19-2006, 07:09 PM
yeah its been a long week 3 comp sci classes this semester. But your right the inc byte I did as a stopgap to fix that I could not increment it because of an error I believe the size was too big or something. But with that fixed I was able to just normally increment. After fudgeing with the code and really getting down and seeing what it was doing, I noticed exactly what you said about the loops, it wasn't saving the variable, so ecx was always zero and the loop keep going.

not about the loops, this was how the professor wanted it. we having got to JNZ yet so I assume he's gonna go there soon.

Its all working, and its good to see I was thinking on the same wavenlength as you.

Thanks for the help

BlueBiker
10-19-2006, 07:26 PM
Kewl, glad you got it working.

You're learning firsthand what people complain about with the irregular x86 instruction set. When certain instructions can only use certain registers, it's a pain to have to keep moving data around to make those registers available.

But assembly is incredibly powerful, and it gives you insight into 'puter architecture like nothing else can. Enjoy!