Author Topic: Calling external library  (Read 2069 times)

Offline josehf34

  • New Member
  • Posts: 1
Calling external library
« on: November 20, 2014, 02:33:17 PM »
Hi guys.

I need to work with the library "id3lib" to load some .mp3 files using NASM, I already installed the id3lib on my ubuntu 14.04 but I don't have idea how should I use this library from NASM, i think maybe "EXTERN" instruction could be involve on this but i need some help

Does someone knows how can I do this?

Offline Mathi

  • Jr. Member
  • *
  • Posts: 79
  • Country: in
    • Win32NASM
Re: Calling external library
« Reply #1 on: November 29, 2014, 10:33:35 AM »
This is just the conversion of a part of demo_simple.cpp  which comes along with id3lib.
The below program displays just the title of the mp3 (not filename) and exits

Code: [Select]
;;Installing ID3Lib
;;sudo apt-get install id3 libid3-dev libid3-doc

;;Assembling and linking
;;nasm -felf32 id3demo.asm
;;gcc -o id3demo id3demo.o -lid3


%define ID3FID_TITLE 47  ;; check globals.h for other field IDs
%define ID3FN_TEXT 2

FIELDLEN equ  1024


;;External library function calls
extern ID3Tag_New
extern ID3Tag_Link
extern ID3Tag_FindFrameWithID
extern ID3Frame_GetField
extern ID3Field_GetASCII
extern printf


section .data

pID3Tag dd 0
pID3Frame dd 0
pID3Field dd 0
filename db "/home/mathi/test.mp3",0  ;;input file name

section .bss
title resb 1024   ;;reserve 1024 bytes


global main
section .text
main:

call ID3Tag_New
mov [pID3Tag], eax

push dword filename
push dword [pID3Tag]
call ID3Tag_Link
add  esp, 4*2     ;;stack balancing

push dword ID3FID_TITLE
push dword [pID3Tag]
call ID3Tag_FindFrameWithID        ;;find the frame with the title
add  esp, 4*2   

mov [pID3Frame], eax

push dword ID3FN_TEXT
push dword [pID3Frame]
call ID3Frame_GetField
add  esp, 4*2
mov [pID3Field], eax

push dword FIELDLEN
push dword title
push dword [pID3Field]
call ID3Field_GetASCII   ;; get the title of the mp3
add esp, 4*3

push dword title
call printf         ;;print the title of the mp3
add esp, 4*1

ret  ;; exit out of main