ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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 ;-)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.