If you're allowed to use the BIOS then it's fairly easy; just write a program in C that does the same, then step through it at the assembler level using the debugger. That'll show you what the standard library does, then you can use that for inspiration.