|
From: Frank K. <fbk...@co...> - 2004-05-03 14:01:49
|
static123ph wrote: > ei can anyone help me... i have this class project and we were > reqiured to amke a program that will convert binary to its octal > equivalent using nasm...help Okay. What parts do you need help with? (I hope "help me" doesn't mean "do it for me"... we're not interested in helping anyone *avoid* learning asm, generally...) Do you know how to do a "convert to decimal"? Same idea, except that you need to divide by 8 instead of 10. Since 8 is a power of 2, we can do the dividing with shifts, instead of that nasty "div" instruction. Or, we could write a routine (or modify the "to decimal" routine, if you've got one) which would accept the base to convert to as a parameter - so with a single routine, we could convert to *any* base - 2, 8, 10, 16... or "oddball" ones, if we want. (there might be a race of seven-fingered people somewhere who would like the answer in "septal" :) To go back to the beginning... I notice you posted this to "nasm-devel" (which is pretty much "dead") as well as to "win32-nasm-users"... do you want this for dos or windows? The "convert" routine would be pretty much the same, but the "inputs" and "outputs" would be different. For a dos program, or windows console mode, you could acquire the number to convert from the command line. Or you could do it "interactive", printing some instructions and getting keyboard input. If you wanted to get *real* pointee-clickee about it, you could let the user select a number to convert by clicking on a number from a list :) Generally, you'll need a routine to get from an ascii string to "binary" (that is, to a "number" - it's the same number with the same value, whether we *represent* it in ascii as "binary", "octal", "decimal" or whatever) Since we're dealing with a "user", we better assume the input is in decimal ascii... Do you know how to do that part? Maybe you should start with something like... mov eax, 42 call my_thingie ; display result - or do you want your routine to do that? ; don't forget to "exit"! Or... how big a number do you want to be able to convert? Maybe "mov al, 42" would be enough?... Or perhaps you want to pass the number to convert on the stack? If you're not going to have the routine print out the number "on the fly", you probably want to pass the "destination buffer" as a parameter, too. If you want to make a "reusable" routine, that will work with *any* base, you'll want to pass the "base" as a parameter. These can all be passed in registers, but if you wanted your routine to be "callable from C", for example, you'd want to pass 'em on the stack. You need to answer questions like these before you start. Or maybe the "assignment" or "program specification" answers 'em. Perhaps implicitly... is early May the beginning of your course, or near the end? What sort of a program you're expected to produce probably depends on that! :) So, what kind of help do you need? (if you don't know where to start, write the comments first - step by step... then see which ones you don't know how to do :) Best, Frank P.S. If this is going to be dos code, it might not really be "on topic" on the win32 list. It would be on topic on the SourceForge "nasm-users" list - which is *not* very active... I'll cc it there - they need the business :) |