LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-07-2004, 06:40 PM   #1
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Rep: Reputation: 47
assembly with masm615


I am having a strange problem, I try to assemble my code and the command prompt changes sizes liek mad then it quits with an error message:
C:\Masm615>make16.bat Assignment7
Assembling: Assignment7.asm
LINK : fatal error L1093: Assignment7.obj : object file not found
Press any key to continue . . .

I have tried everything I can think of, as well as trying to compile it on different computers (all intel based on windows)

here is my code, I don't expect it to be free of bugs, or efficient yet, usually I make something work first, but I am stuck on that last part.

Code:
TITLE Assignment7              (Assignment7.asm)

; This program takes a string and deturmines weather or not it is a palendrome.
; 

INCLUDE Irvine16.inc

.data
Prompt BYTE "Please enter a possible Palendrome: ",0	;prompt message
IsPalendrome BYTE "Yes that is a palendrome!",0		;messaage if a palendrome is found
NotPalendrome BYTE "No that is not a palendrome.",0	;message if it is not a palendrome
UserInput BYTE 79 dup(0) ;create a buffer for user input with one digit more than max size so that it always ends with 0 null

.code
main PROC
	mov ax,@data
	mov ds,ax

PROMPTUSER:
	mov dx, OFFSET Prompt	;Move the offset of the prompt message into dx
	call WriteString	;print the message

;Read user input
	mov cx, 78		;move the maximum allowed characters into cx
	mov dx, OFFSET UserInput	;move the offset of the userinput buffer to dx
	call ReadString			;read the user input
;check user input
	mov si, OFFSET UserInput	;put the offset of UserInput into si
	mov bx, [si]			; move th efirst character of UserInput into bx
	cmp bx, 0	;If the string is empty (starts with 0 null)
	je ENDPROG	;end the program	

;print the string back to the user
	mov dx, OFFSET UserInput	;move the offset of the input string into dx
	call WriteString		;print the string

;Check for trivial case of 1 character string
	mov si, OFFSET UserInput	;Place the offset of the UserInput string into ax
	mov bx, [si + 1]		;get the second byte of the userinput string/array
	cmp bx, 0 ;Check if the string is only 1 digit long (second byte is 0 null)
	je NOTP		;announce hat we do not have a palendrome

;Check if we have a palendrome
	mov dx, OFFSET UserInput ;move the offset of the user input into dx
	call Check		;call the Check subroutine
	cmp ax, 0		;compare ax to 0 (0 is not a palendrome, 1 is)
	je NOTP			;Not a palendrome, announce it.
ISP:
	mov dx, OFFSET IsPalendrome ;Move the offset of the IsPalendrome message to dx
	call WriteString		;Print the message
	jmp PROMPTUSER			;prompt again
NOTP:
	mov dx, OFFSET NotPalendrome	;Move the offset of the NotPalendrome message to dx
	call WriteString		;Print the message
	jmp PROMPTUSER			;Prompt again
ENDPROG:
	exit				;end the program
main ENDP

.data
CloneA BYTE 79 dup(0) ;place to store striped string
CloneB BYTE 79 dup(0) ;place to store reversed string

.code
Check PROC uses dx si bx
;takes the offset of a string in dx
;return 0 if the string is not a palendrome
;returns 1 id the string is a palnedrome
;returns are stored in ax

;Uppercase all characters
	mov cx, LENGTHOF CloneA		;Put the length of cloneA into the counter (cx)
	mov si, dx			;mov the offset of UserInput as passed through dx into si
CaseLoop:
	AND byte ptr [si], 11011111b	;uppercase all lowercase characters, we do not care about non alpha characters
	inc si				;incriment to next element in string
	loop CaseLoop			;loop again

;Strip out unnecessary characters
	mov si, dx			;mov the offset of UserInput as passed through dx into si
	mov di, OFFSET CloneA		;mov the offset of CloneA into di
StripLoop:
	mov ax, [si]	;move the first element of UserInput into ax
	cmp ax, 0	;compare ax to null0
	je EndStrip	;if the element is 0 end the stripping
	cmp ax, 'A'	;compare the element to 'A'
	jb NEXT		;if the element is a character lower than A on the ascii scale jump to next
	cmp ax, 'Z'	;compare the element to 'Z'
	ja NEXT		;if the element is above Z on the ascii scale jump to next
	mov ax, [si]	;place the element into the CloneA string
	mov [di], ax	;"		"
	inc di		;incriment to next element of CloneA
NEXT:
	inc si		;incriment to next element of UserInput
	jmp StripLoop	;Re-Loop
EndStrip:

;copy the string in reverse from CloneA into CloneB
	mov cx, LENGTHOF CloneA ;Set the counter to the length of CloneA
	mov ax, OFFSET CloneA	;Set ax to the offset of CloneA
	add ax, LENGTHOF CloneA ;add the Lengthof cloneA to ax so we start at the end of it
	mov si, ax		;move the value in ax to si
	mov di, OFFSET CloneB	;set x to the beginning of CloneB
ReverseLoop:
	mov ax, si
	cmp ax, 0 ;compare ax to 0
	je NextLoop ;if ax is 0 jump to the next loop
	mov dx, [si] ;mov the element of UserInput into dx
	mov [di], dx ;move dx into the element of bx
	inc di		;incriment to the next element in bx
NextLoop:
	dec si		;decriment to the next element of ax
	loop ReverseLoop	;next loop

;Compare strings

;print the 2 strings so I can confirm a hit or miss for testing purposes
	mov dx, OFFSET CloneA
	call WriteString
	mov dx, OFFSET CloneB
	call WriteString

	mov si, OFFSET CloneA	;Place the offset of CloneA into dx
	mov di, OFFSET CloneB	;place the offset if CloneB into bx
	mov ax, 1		;mov 1 into ax (for return)
CompLoop:
	mov bx, [si]	;move the current element of CloneA into bx
	mov dx, [di]	;move the current element of CloneB into dx
	cmp bx, dx	;compare dx and bx
	jne NEQUAL	;if the characters are nto equal we have no palendrome, return 0
	inc si		;incriment to next character of CloneA
	inc di		;incriment to next character of CloneB
	loop CompLoop	;Reloop
	ret		;return 1 when finished
NEQUAL:
	mov ax, 0	;set ax to 0
	ret		;return
Check ENDP
END
oh and irvine16.inc is the readstring and writestring routines, I know that is correct and I know I called those correctly so you can ignore those.

Last edited by exodist; 11-07-2004 at 06:43 PM.
 
Old 11-08-2004, 01:42 AM   #2
krupa
LQ Newbie
 
Registered: Sep 2003
Posts: 6

Rep: Reputation: 0
I only know GAS syntax, so I'm gonna ask a stupid question here... which register is "si" and why are you using it?
 
Old 11-08-2004, 08:33 AM   #3
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
si and di (32-bit is esi and edi) are used by high speed memory transfer instructions, aka extended source index and extended destination index, they are labeled as general purpose registers like ax dx, etc.
 
Old 11-08-2004, 11:47 PM   #4
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
fixed, the filename Assignment7.asm is too long for 16 bit dos, so it caused issues. renamed to smaller name and it assembled and linked fine, now to debug ;-)
 
Old 11-09-2004, 10:14 PM   #5
laksi
LQ Newbie
 
Registered: Aug 2004
Posts: 8

Rep: Reputation: 0
Thumbs up

similar to my previous project;
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
assembly ? blackzone Programming 3 10-15-2004 02:36 AM
Assembly jinksys Programming 3 09-14-2003 04:33 PM
I need help for Assembly skb Programming 10 08-01-2003 04:51 PM
assembly genghis Programming 2 06-12-2003 07:46 AM
assembly sanjay pradhan Programming 1 02-01-2002 10:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration