Hello,
How can I reverse the code in the example?
How would it be to convert multiplication into division in particular?
invoke GetDlgItemText,hWin,offset edtvalue,offset value,sizeof value
mov ecx,eax
lea esi,dword ptr ds:[value]
xor edx,edx
xor eax,eax
xor edi,edi
@_atl1:
mov AL,0Ah
mov dl,byte ptr ds:[esi]
test dl,dl
je @_atl2
sub dl,10 ; add
imul edi,eax ; div or idiv ??????????????
welcome to forum kesmezar
difference between idiv and div is work on signed or unsigned integer
div works on eax:edx, so you should clear edx before div and check for divide by zero before
You can convert a multiplication into a division by changing 0Ah into a reciprocal.
AL = 10
DL = 50
50 * 10 = 500
AL = 0.1 ( reciprocal: 1 / 10 = 0.1 )
DL = 50
50 / 0.1 = 500
Or change a division into a multiplication:
reciprocal of 0.1: 1 / 0.1 = 10
It is faster to use multiplications instead of divisions.
You can also use "magic numbers" : http://masm32.com/board/index.php?topic=1906.0
It appears that what you have there is a string to number exercise and your instructor wants you to produce a string from a number. :skrewy:
Quote from: AW on February 20, 2020, 04:10:40 AM
It appears that what you have there is a string to number exercise and your instructor wants you to produce a string from a number. :skrewy:
yes its often newbie exercises seen ,but I want the teacher to make the most of the training to become a programmer to exercise 1a:solve with code only a problem,1b:solve it with help of research right library functions/macros and use that in a second version
Thank you for your help.
The work done by the code in my first message. :)
A587 (Hex)
(41 - 30) + (0 * A) = 11
(35 - 30) + (11 * A) = AF
(38 - 30) + (AF * A) = 6DE
(37 - 30) + (6DE * A) = 44B3
;--------------------------------------------------------
A587 (Dec)
(65 - 48) + (0 * 10) = 17
(53 - 48) + (17 * 10) = 175
(56 - 48) + (175 * 10) = 1758
(55 - 48) + (1758 * 10) = 17587
If you type "A587" it creates "44B3".
You should get "A587" for "44B3". :(
44B3 hex = 17587 dec
Quote
I created this algorithm.
Well, it looks like an absolute nonsense to me. Why are you dividing by 10 a number in base 10 and in the end obtain A. 17 is not A.
WTF.
Note that lots of geniuses come to this forum, almost every week we receive one or two. So, you need to explain slowly what you are doing. :skrewy:
I do not fully understand you. I am trying to deal with Google translete.
I think we will get along if I change my messages
17587 / 10 = 1758,7 => 7 + 48 = 55 (55 dec = char 7)
1758 / 10 = 175,8 => 8 + 48 = 56 (56 dec = char 8)
175 / 10 = 17,5 => 5 + 48 = 53 (53 dec = char 5)
A is a fixed value. => mov AL,0Ah
785A => reverse A587.
I created this solution. I got stuck on how to write with Masm32. For example, I should be able to find and proceed with MODulo remaining operation.
I may not be successful, but you can offer a better algorithm.
You want to swap 4 nibbles?
Is this a school exercise?
mov ax,785Ah
first exchange the 2 bytes, al and ah ( -> 5A78h )
you can load the 2 bytes separately or use the "xchg" instruction on ax
Then make 1 copy of ax to another register, cx for example.
shift ax 4 bits to the left.
clear nibble 0 and 2 ( use the "and" instruction )
shift cx 4 bits to the right.
clear nibble 1 and 3 ( use the "and" instruction )
add cx to ax.
ax is now: A587h
Quote from: kesmezar on February 23, 2020, 06:34:35 AM
I do not fully understand you. I am trying to deal with Google translete.
I think we will get along if I change my messages
17587 / 10 = 1758,7 => 7 + 48 = 55 (55 dec = char 7)
1758 / 10 = 175,8 => 8 + 48 = 56 (56 dec = char 8)
175 / 10 = 17,5 => 5 + 48 = 53 (53 dec = char 5)
A is a fixed value. => mov AL,0Ah
785A => reverse A587.
I created this solution. I got stuck on how to write with Masm32. For example, I should be able to find and proceed with MODulo remaining operation.
I may not be successful, but you can offer a better algorithm.
there is string macros that can help you in masm,if you turn it into a string its easier to just reverse string
Note that the string macros are used in the function position which means they can be assigned to variables or used within more complex macros if the differences are properly understood.
Normal string macros
add$ Join two strings by appending the second onto the first
append$ Append a zero terminated string and return next position
cat$ Join multiple strings to a user defined buffer
chr$ Return the address of combined quoted strings and bytes
cmp$
Compare strings (case sensitive).
cmpi$
Compare strings (case insensitive)
cfm$ Format a quoted string with C style escapes
ptr$ Cast a buffer to a pointer
len Return the length of a zero terminated string
find$ Find a substring in a source string
lcase$ Convert string to lower case
ucase$ Convert string to upper case
left$ Read characters from left side of string
remove$ Remove sub string from source string
right$ Read characters from right side of string
ltrim$ Trim the left side of a string of spaces
rtrim$ Trim the right side of a string of spaces
trim$ Trim both ends of a string of spaces
rev$ Reverse a string
cmd$ Get the address of a command line argument. ASCII only
ucCmd$
Get the address of a command line argument. UNICODE only
Integer to string conversions
ustr$ Convert unsigned 32 bit integer to a zero terminated string
sstr$ Convert signed 32 bit integer to a zero terminated string
uhex$ Convert unsigned 32 bit integer to a zero terminated hex string ASCII only.
hval Convert hex string to 32 bit integer ASCII only.
String to integer conversions
sval Convert signed string to 32 bit signed integer
uval Convert unsigned string to 32 bit unsigned integer
@Siekmanski,binary coded decimals used to for example calculate lots of decimals of pi,raymond has tutorial on BCD's,I got inspired by this thread to see if it would be possible to speed up BCD divisions
so I started this tests:
http://masm32.com/board/index.php?topic=8361.msg91642#new (http://masm32.com/board/index.php?topic=8361.msg91642#new)