The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Other Programming Languages
|
Assembly - Rotation/String Problem - NASM
Discuss Rotation/String Problem - NASM in the Other Programming Languages forum on Dev Shed. Rotation/String Problem - NASM A place for discussing programming languages not covered in specific forums such as Assembler, COBOL, etc. - you get the idea.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 9th, 2012, 11:22 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 2
Time spent in forums: 35 m 57 sec
Reputation Power: 0
|
|
|
Assembly - 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
|

February 10th, 2012, 06:29 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 2
Time spent in forums: 35 m 57 sec
Reputation 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!
Quote: | 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 |
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|