1 Replies - 9694 Views - Last Post: 23 October 2013 - 07:43 PM

#1 zhengliang  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-October 13

How to write a revers string in x86 assembly language!~~

Posted 23 October 2013 - 03:12 PM

Hello everyone, this is my first semester in assembly language. And i just got the homework to write a " Reverse string" program by using the "MACRO, and swaps the characters a and b in place using the XOR instruction" This is what i did but it doesn't work.. I want help me fix the program and tell me what i did wrong!!~~~

TITLE ReadStringProc (ReadStringProc.asm)



include irvine32.inc

.data
	input  byte 50 dup(0)                         
	;byteCount DWORD ?                             
	EnterName byte "Enter your  Name: ",0         
	total byte "The total is: ",0		      
	

.code 


mWriteString MACRO name
	push edx
	mov edx, offset name
	call writeString
	pop edx
endM	


mReadString MACRO name
	push ecx
	push edx
	mov edx, offset name
	mov ecx, sizeof name
	call readstring
	
	pop edx
	pop ecx
endM




strlen proc
	push ebp
	mov ebp, esp
	push ebx
	push ecx
	mov eax, 0
	mov ebx, [ebp+8]

loops:
	mov cl, [ebx]
	cmp cl, 0
	JE endLoop
	
	add ebx, 1
	add eax, 1
	jmp loops

endLoop:
	pop ecx
	pop ebx
	pop ebp

	ret 4

strlen endp




swap MACRO first,last
	push eax
	
	mov ah, first
	mov al, last

	xor al, ah
	xor ah, al
	xor al, ah
	
	mov last, al
	mov first, ah
	
	pop eax
endM


strrev proc
	push ebp
	mov ebp, esp
	push ebx
	push ecx
	push [ebp+8]

	call strlen
	
	mov ebx, [ebp+8]
	mov ecx, [[ebp+8]+ebx-1]



reverseLoop:	
	jz done

	mov ah, [ebx]
	mov al, [ecx]
	
	swap ah, al

	mov [ebx], ah
	mov [ecx], al
	
	inc ebx
	dec ecx
loop reverseloop

done:
	
	pop [ebp+8]
	pop ecx
	pop ebx
	pop ebp
	
	
	ret 4



strrev endp



Main proc

	call clrscr				
	mov edx, offset EnterName		
	call writeString
	
	mReadString input
	push offset input
	call strlen
	
	mWriteString input
	
	call crlf
	
	mov edx,offset total
	call writestring

	call writedec	

	call crlf
	
	push offset input
	call strrev

	;mWriteString input
	
	
			
exit 
main endp




end main


Is This A Good Question/Topic? 0
  • +

Replies To: How to write a revers string in x86 assembly language!~~

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 917
  • View blog
  • Posts: 2,358
  • Joined: 28-March 11

Re: How to write a revers string in x86 assembly language!~~

Posted 23 October 2013 - 07:43 PM

First off, most dialects of x86 Assembly are strict on the case of variables/procedure names/names in general. reverseLoop is not the same as reverseloop as on line 99 and 112. On line 134 you do call writeString but on line 145 you do call writestring Line 130 you have Main proc but close it with main endp and end main

Mr. Irvine created and named the functions:
WriteString, Crlf, WriteDec, ReadString, and Clrscr this is to help prevent bugs in your code. I refuse to fix the 9 or so errors just to get your code to Assemble, please fix the errors MASM SHOULD be giving you, and repost the corrected code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1