The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Pro32 on April 01, 2005, 10:17:27 PM

Title: printing backwards
Post by: Pro32 on April 01, 2005, 10:17:27 PM
Can someone show me how to print backwards. I'm making a program that uses one prompt to as the user for their name: Last Name, First Name. But I want it to print First Name Last Name. How can I go about this.
Title: Re: printing backwards
Post by: sluggy on April 01, 2005, 10:35:50 PM
You need to re-word your question... to do it as you've asked is to break the laws of physics, as you want to print something the user hasn't typed yet.....

You need to wait till the user has input their whole name, then you just slice'n'dice the string and output it. You really should write the code first, and then if you still need guidance then ask some more questions.
Title: Re: printing backwards
Post by: Tedd on April 02, 2005, 10:44:28 AM
1. Get user's input
2. Check each character in the string until you get to ',' (call this position n)
3. buff[n] = (byte)0
4. print_string(buff[n+2])
5. print_string(buff[0])
6. Learn to do your own homework :bdg
Title: Re: printing backwards
Post by: Pro32 on April 02, 2005, 05:55:47 PM
Quote from: Tedd on April 02, 2005, 10:44:28 AM
1. Get user's input
2. Check each character in the string until you get to ',' (call this position n)
3. buff[n] = (byte)0
4. print_string(buff[n+2])
5. print_string(buff[0])
6. Learn to do your own homework :bdg


So your saying its very similar to the program I have here. Instead of checking for ',' , I should check for blank spaces. And what is buff?

INCLUDE Irvine32.inc


.data

sentence BYTE "THIS IS MY SECOND ASSIGNMENT!!!"
sentence1 BYTE 30 DUP (?)

.code
main PROC
;this prints the original sentence
mov edx, OFFSET sentence
call WriteString
call Crlf


;Print sentence in  Lowercase letters
mov ecx, LENGTHOF sentence1
mov esi, 0
mov al,0

L1:
mov al, sentence[esi]
cmp esi,0
je NoUpperCase ;for the first symbol

cmp al,41h
jl NoUpperCase ; if less then 'A'

cmp sentence[esi-1],20h  ;checks if previous character was a space
jz NoUpperCase
add al,32d


NoUpperCase:
mov sentence[esi], al
inc esi
loop L1


call WriteString
call Crlf

exit
main ENDP
END main
Title: Re: printing backwards
Post by: thomasantony on April 03, 2005, 03:07:08 AM
Hi,
    buff is a memory buffer where the string is stored. and again
Quote
Learn to do your own homework

Thomas
Title: Re: printing backwards
Post by: Tedd on April 03, 2005, 10:04:24 AM
Quote from: Pro32 on April 02, 2005, 05:55:47 PM
So your saying its very similar to the program I have here. Instead of checking for ',' , I should check for blank spaces. And what is buff?
  .
  .

Yes, it's a similar kind of thing.
"Buff" is just the name of the buffer/array to store the user's input in. You could just call it "username" or whatever.

Just have a go at it, if you get stuck - no problem; we don't mind helping. But HAVE A GO :P
The best way to learn is to try it and get it wrong and then work out how to fix it :cheekygreen: