#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Rotation/String Problem - NASM


    Hey,

    I've run into a small problem with the loop that I have, the ror command does fine rotating the bits of:

    1000 0000

    Until it gets to the end of the byte and it just prints out 0's after.

    Code:
    PutStr prompt1_msg
    		nwln
    		GetStr inputString
    		PutStr inputString_test
    		nwln
    		PutStr inputString
    		nwln
    
    ; loop start
    
    		mov cx, 16
    
    		
    		xor ebx, ebx
    		xor eax, eax
    
    		mov al, [bitValues]
    
    		start_of_loop:
    
    			PutLInt eax
    			nwln
    
    			; Find the bit value of the inputted letters
    			mov bl, [inputString]
    			PutStr andBitwise_op	
    			nwln
    
    			; 'and' the results...
    			and bl, al
    			;cmp al, 0
    			jz jump_notOne 
    
    			jump_one:
    			PutStr bitValue_oneEntered
    			jmp jump_Exit
    
    			jump_notOne:		
    			PutStr bitValue_zeroEntered
    
    			jump_Exit:
    			rcr eax, 1
    			nwln
    			
    			dec cx
    			cmp cx, 0
    			jnz start_of_loop
    			
    		exit_loop:
    		PutStr endOfLoop_reached ; end of looping over bits
    		nwln
    Now I've narrowed my problem down to 2 things:
    1) The way I've stored my 2 input characters, as a character string isn't properly reading input
    2) The ror isn't working the way it should

    I am leaning more towards (1) but I am sort of stumped. The idea with this is I am checking each of the bits, via and, to put the bits into an array after. The problem only starts after the 8th bit.

    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0
    Well, seeing as nobody checks this forum often, I will just post this up for some other person to stumble upon someday and hope it helps:

    Code:
                    ; ----------------
    		; Step #1:
    		; Get String Input
    		; ----------------
    		PutStr promptInput_msg
    		nwln 
    		GetStr inputString
    		PutStr inputString_test
    		nwln 
    		PutStr inputString	
    		nwln
    		; ----------------
    		; End of Step #1
    		; ----------------
    
    		; ----------------
    		; Step #2:
    	    ; Transmit bit by bit into an array of 2 bytes (16 bits) to contain both
    		; inputted characters
    		; ----------------
    
    		; clear the registries before using
    		xor ax, ax
    		xor bx, bx
    		xor cl, cl
    		xor dx, dx
    		xor esp, esp
    
    		mov cl, 16
    		mov ax, [inputString]
    		mov bx, 1000000000000000B
    		mov esp, unpackArray
    
    		PutStr looping_start
    		nwln
    
    		start_of_loop:
    
    		mov dx, bx
    		
    		and dx, ax
    		cmp dx, 0
    		jz jump_zero
    
    		PutStr bitValue_oneEntered
    		; enter value into array
    		mov [esp], byte 1
    		jmp jump_Exit
    
    		jump_zero:
    		PutStr bitValue_zeroEntered
    		; enter value into array		
    		mov [esp], byte 0	
    		
    		jump_Exit:
    		nwln
    		inc esp
    		dec cl
    		ror bx, 1
    		jnz start_of_loop
    
    		PutStr endOfLoop_reached
    
    		; ----------------
    		; End of Step #2
    		; ----------------
    This code is using a mask to check the value of the input string at each bit, and return either a 0/1 that is placed into a seperate array. The initial problem with the code was that I was using a 8bit model to compare against the 16 bits of the inputString.

    I will explain now the problems I had run into and what I did to fix them. Basically the problem I had was not managing the registries properly and overwriting some of them with other values, or putting values into registries that didn't have the proper size.

    I simple terms, just using registry A* for instance:
    AL, AH (A-low, A-high) each only hold 1 byte (8 bits) so they are useful for only holding things with 8 bit positions or 1 character.
    AX is basically AL and AH combined, so it allows, yup, 2 bytes (16 bits) to be used.
    EAX is is extended A which holds even more and so forth...

    For simplicity's sake, you are alotted registries A-D in each of these cases which the exception of some others that you can look up on the web.

    So when coding in Assembly you have to mind your registry management, I'd strongly suggest mapping out on paper first!

    Originally Posted by D1sciple1337
    Hey,

    I've run into a small problem with the loop that I have, the ror command does fine rotating the bits of:

    1000 0000

    Until it gets to the end of the byte and it just prints out 0's after.

    Code:
    PutStr prompt1_msg
    		nwln
    		GetStr inputString
    		PutStr inputString_test
    		nwln
    		PutStr inputString
    		nwln
    
    ; loop start
    
    		mov cx, 16
    
    		
    		xor ebx, ebx
    		xor eax, eax
    
    		mov al, [bitValues]
    
    		start_of_loop:
    
    			PutLInt eax
    			nwln
    
    			; Find the bit value of the inputted letters
    			mov bl, [inputString]
    			PutStr andBitwise_op	
    			nwln
    
    			; 'and' the results...
    			and bl, al
    			;cmp al, 0
    			jz jump_notOne 
    
    			jump_one:
    			PutStr bitValue_oneEntered
    			jmp jump_Exit
    
    			jump_notOne:		
    			PutStr bitValue_zeroEntered
    
    			jump_Exit:
    			rcr eax, 1
    			nwln
    			
    			dec cx
    			cmp cx, 0
    			jnz start_of_loop
    			
    		exit_loop:
    		PutStr endOfLoop_reached ; end of looping over bits
    		nwln
    Now I've narrowed my problem down to 2 things:
    1) The way I've stored my 2 input characters, as a character string isn't properly reading input
    2) The ror isn't working the way it should

    I am leaning more towards (1) but I am sort of stumped. The idea with this is I am checking each of the bits, via and, to put the bits into an array after. The problem only starts after the 8th bit.

    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo