Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


I need help with assembly

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
MaximuS
I post too much
Reputation: 3

Joined: 05 Apr 2007
Posts: 3212
Location: ......

PostPosted: Fri Feb 13, 2015 4:43 am    Post subject: I need help with assembly Reply with quote

I provided my assignment sheet below. I need a lot of help. I've been getting a little confused with assembly compared to other languages. I'd be grateful if someone would help.


For the first part:
" Write a macro, senary2int, to convert a string of ASCII
digits representing the senary value into an integer. The
macro arguments are starting address of string, integer (for
result), and string length."

I have no idea if I am doing this right anymore, but here's my code.
Format of the macro is as follows:
; Call: senary2int <string>, <integer>, <stringLength>
; Arguments:
; %1 -> <string>, string address
; %2 -> <integer>, address (for result)
; %3 -> <stringLength>, immediate value

Code:
%macro   senary2int   3
   push   rcx
   push   rsi
   push   rdi

   
mov rcx,%3
mov rax, 0
mov eax, 1
startLoop:
   mov ebx, %1
   sub ebx, 48
   mul ebx, eax
   mul eax, 6
   add rax, ebx
   cmp rcx, 0
   jne startLoop
   mov %2, rax

   
   pop   rdi            ; restore original register contents
   pop   rsi
   pop   rcx
%endmacro


I also need help with the other macro which is from integer to senary ascii.

Write a macro, int2senary, to convert an integer into a
string of ASCII digits representing the senary value. The macro arguments are integer and
starting address of string (for result). The ASCII string should include only the ASCII digits (no
spaces or leading zero's).


Thank you so much, I need help ASAP.[/code]
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25794
Location: The netherlands

PostPosted: Fri Feb 13, 2015 6:07 am    Post subject: Reply with quote

ok, so senary is base-6 (going from 0 to 5, to 0,1,2,3,4,5,10,11,12,13,14,15,20,...)

senary to int:
example: '115'
5*(6^0)+1*(6^1)+1*(6^2)=8*1+1*6+1*36=5+6+36=47

I don't have much experience with macro usage so I will have some things wrong, but looking at your code (i'm not sure how the parameters are passed when using macro's registers or static addresses ?)

in the loop ebx gets the address of the first byte of the string (formatted ascii)

First off, this is going to cause an issue seeing you use 64-bit registers. The address of the string could be in a memory block of 0x100000000 or higher, and then cause a crash


I'll try to edit your code and place some comments. It's untested and highly unlikely to function, but it might make things more clear (and can probably be optimized)
Code:

%macro   senary2int   3
  push   rbx
  push   rcx
  push   rdx
  push   rsi
  ;also save rax?

mov rcx,%3 ;rcx gets the count in bytes
mov ebx, 0 ;temporary storage for the result (best not use rax due to mul)
mov rsi,%1 ;rsi now points to the start of the string
add rsi,rcx ;rsi now points behind the last character of the string
sub rsi,1 ; rsi now points to the last character of the string

mov edx,1 ;current multiplier

startLoop:
   movzx edx,[rsi] ;place the byte stored in esi into al and zero the other bytes (otherwise mov eax,0 -  mov al,[rsi] )
   sub eax,48 ;subtract the ascii char value of '0'(48) from it. '0' becomes 0, '1' becomes 1 , etc...  (sub al,48 works too)

push edx ; quick edit, I forgot mul touches edx too
   mul edx ; multiple the value stored in eax with the current multiplier (1, 6, 36, 216, ...) The result will go into eax and edx
pop edx

   add ebx,eax ;add the value to the result

   ;multiply the current multiplier with 6  (1->6->36->216)
   mov eax,edx
   mul eax 
   mov edx,eax

    sub rsi,1 ; go to the next char

   loop startLoop ;this will decrease rcx with 1 and jump to startLoop when it's not 0

   mov %2, rdx

  pop rsi
  pop rdx
  pop rcx
  pop rbx
%endmacro



inttosenary is probably
47 mod 6= 5 <
47 div 6 = 7

7 mod 6 = 1 <
7 div 6 = 1

1 mod 6 = 1 <
1 div 6 = 0


(so 115)

fun thing about div is that it returns both the div and mod result at the same tim

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
MaximuS
I post too much
Reputation: 3

Joined: 05 Apr 2007
Posts: 3212
Location: ......

PostPosted: Fri Feb 13, 2015 6:43 pm    Post subject: Reply with quote

So the string parameter thats being passed is for example "00000123", NULL
How would you go about that? The same way?
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25794
Location: The netherlands

PostPosted: Fri Feb 13, 2015 7:42 pm    Post subject: Reply with quote

assuming the stringlength passed is 8 yes

otherwise i'd add in a scan for NULL and start from there

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
MaximuS
I post too much
Reputation: 3

Joined: 05 Apr 2007
Posts: 3212
Location: ......

PostPosted: Fri Feb 13, 2015 8:59 pm    Post subject: Reply with quote

This has seemed to compile without issue. I'm having problems with the debugger now.
Code:

%macro   senary2int   3
   push   rcx
   push   rsi
   push   rdi

   
mov rcx, %3
mov eax, 0
mov rsi, 0
mov rbx, %1
mov r8d, 6
;add rsi, rcx
;sub rsi, 1
%%startLoop:
   mov bl, byte [rbx+rsi]
   sub bl, 48
   mul r8d
   add eax, ebx
   inc rsi
   loop %%startLoop
   mov [%2], ebx

   
   pop   rdi            ; restore original register contents
   pop   rsi
   pop   rcx
%endmacro


But my next issue is the integer to senary.
Code:

;  Macro to convert integer to senary value in ASCII format.

;  Call:  int2senary    <integer>, <string-addr>
;   Arguments:
;      %1 -> <integer>, value
;      %2 -> <string>, string address

;  Reads <string>, place count including NULL into <count>
;  Note, should preserve any registers that the macro alters.
;   YOUR CODE GOES HERE
mov eax, %1
mov r9d, 6
convLoop:
   div r9d
   add edx, 48
   push edx
   cmp eax, r9d
   jge convLoop
   

What I'm trying to do is in order to convert base 10 to base 6, I divide by 6 and the remainder is then pushed into a stack.
I'm wondering how do you pop it at the end in order to have it placed into a string
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25794
Location: The netherlands

PostPosted: Fri Feb 13, 2015 9:05 pm    Post subject: Reply with quote

i would compare if eax is bigger than 0 instasd of 6 since the mod of any value smaller than 6 is still a result

as for getting the result, try keeping a counter and then pop them that amount of times from the stack and append every result to the output string memory

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
MaximuS
I post too much
Reputation: 3

Joined: 05 Apr 2007
Posts: 3212
Location: ......

PostPosted: Fri Feb 13, 2015 9:26 pm    Post subject: Reply with quote

Is it applied like this
Code:

mov eax, %1
mov r9d, 0
mov rsi, 0
convLoop:
   div r9d
   add edx, 48
   push edx
   inc rsi
   cmp eax, r9d
   jge convLoop
   
mov rcx,rsi
addString:
   pop edx
   mov ebx, edx
   add byte [tmpString+rsi]
   dec rsi
   loop addString
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites