|
|
|||||||
| About Us | Register | FAQ | Members List | Calendar | Mark Forums Read |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2002
Location: Mexico City, Mexico
Posts: 5,565
|
Assembly help...
Ok as this month task i have to program the Hanoi towers in assembly... my only problem is that i pretty noobish in using extern function in asm files, so id ask for any advice you can give
![]() My C++ calling program #include [iostream.h] #include [stdio.h] #include [stdlib.h] extern "C" int n; extern "C" void principal(); int main(void){ cout <<"Numero de discos\n "; cin >> n; principal(); return 0; } The asm module extern printf global _n global _principal section .data ind dd 0 ;;i use the indicator as a medium to know when to use the base ;; ;; case _n dd 0 temp dd 0 fmt: db "se mueve %d del palo %d al palo %d", 10, 0 section .text _principal mov ax,1 mov bx,2 mov cx,3 mov dx,[_n] Hanoi: mov ax,1 cmp [ind],ax JNZ general push dx ;;base case, we move one disk from one stick to another push ax push cx call printf ;;im asumming that the printf function gets the pops anyway ;; from what i've read ret ret ;;when we are done we return the control to C++ Code continues later about the general case the error i am getting is Linking... proyecto.obj : error LNK2001: unresolved external symbol printf Debug/Ensamblador.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. Ensamblador.exe - 2 error(s), 0 warning(s) Any clues? ![]() EDIT: aaa...nm i realized the mistake. it was _printf
__________________
Last edited by Proto; April 3rd, 2004 at 17:07. |
|
|
|
|
|
#2 (permalink) |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2002
Location: Mexico City, Mexico
Posts: 5,565
|
Sorry for double posting but i have another problem. The printf function called from the asm doesnt... print anything
Can you point me out any mistakes you see pleaseextern _printf global _n global _principal section .data ind dd 0 ;;con este sabremos si solo se va a mover un disco _n dd 0 ;;numero de discos temp dd 0 text: db "se mueve %d del palo %d al palo %d", 10, 0 section .text _principal mov ax,1 mov bx,2 mov cx,3 mov dx,[_n] mov [ind],dx Hanoi: mov [temp],bx mov bx,1 cmp [ind],bx mov bx,[temp] JNZ general push dx push ax push cx call _printf pop bx pop bx pop bx ret ret ;;regresa al modulo de c++ general: ---------
__________________
Last edited by Proto; April 3rd, 2004 at 19:49. |
|
|
|
|
|
#3 (permalink) |
|
Da Ultimate Noob Molester
![]() ![]() Join Date: Sep 2003
Location: Los Angeles - CA
Posts: 125
|
Well, could be either one of the following things:
- You are not pushing the parameters used by printf in the right order (last argument ought to be pushed first). - Also, I believe you are trying to print the string found inside text, but you haven't actually pushed a pointer to that string. Try something like this: mov si, text ;stores the address of text in si ... push si ;passes the parameter to the printf function. Before you do any of this, however, remember to save the contents of things like bp, sp, si, and di (hell, you might as well just do a pusha right at the beginning of the function) Hope this helps. PS.: if you have any questions regarding assembly programming visit http://assembly.conforums.com/ EDIT: Like I thought, you only pushed *three* parameters instead of four! |
|
|
|
|
|
#6 (permalink) |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2002
Location: Mexico City, Mexico
Posts: 5,565
|
Hmmm....i dont remember well...i guess it was because i was thinking that the pusha and popa only worked with the 16 bit part.... anyway im done with my code (it works now),here it is for those who need it (yeah sure
)Code:
extern _printf
global _n
global _principal
section .data
ind dd 0 ;con este sabremos si solo se va a mover un disco
_n dd 0 ;numero de discos
temp dd 0
text db 'se mueve %d del palo %d al palo %d', 10, 0
section .text
_principal
mov ax,1 ;;se usan los registros para representar los palos
mov bx,2
mov cx,3
mov dx,[_n] ;;en dx se guarda el numero de discos
mov [ind],dx
Hanoi:
mov [temp],bx
mov bx,1
cmp [ind],bx ;;si ind vale uno es que solo se mueve un disco
mov bx,[temp]
JNZ general
pusha
push ebp
mov ebp,esp
mov [temp],cx
push dword [temp] ;;caso base Se lee: Se mueve el disco edx de eax a ecx
mov [temp],ax
push dword [temp]
mov [temp],dx
push dword [temp]
push dword text
call _printf
mov esp,ebp
pop ebp
popa
ret
ret ;;regresa al modulo de c++
general:
pusha ;; movemos n-1 al palo auxiliar
mov [temp], bx
mov bx, cx
mov cx, [temp]
dec dx
mov [ind],dx
call Hanoi
popa ;; uno al palo final
pusha
mov [temp],bx
mov bx,1
mov [ind],bx
mov bx,[temp]
call Hanoi
;;n-1 al palo central
popa
mov [temp], ax
mov ax, bx
mov bx, [temp]
dec dx
mov [ind], dx
call Hanoi
ret
__________________
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|