The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
Trying to print integers out of an array to the screen (or file) and my book is too vague as to be unhelpful, and I can't find anything useful googling.
Anyone know the proper interrupt and function code, and how to use it?
I'm using Borland TASM circa 1990, doing 16-bit applications for x86 architechture.
Why do most universities force you to learn the most outdated asm possible? Guess what, assholes, asm isn't like other code: once it's outdated, the skills you learn don't really translate well into modern programming. Nobody writes code for a fucking 286 anymore! It's not that hard to just throw a student into a modern computer's asm. They'll handle it, I promise!
Ahem. Anyways.
I don't know if the 1990 Borland assembler will let you do this, as when I took an ASM class we used an up-to-date version of gcc on a modern, 32-bit computer, like rational people, but you just call the printf function to print stuff to the screen, just like in C. In asm, you pass variables to a C function by pushing them to the stack in reverse order. Example: let's say eax (or, shit, you're in 16-bit, so just ax) has the memory address of a string. You use:
push ax
call prinf
pop ax
and you're good. Don't forget to do that pop, or you'll leave the stack unbalanced.
I'm using Borland TASM circa 1990, doing 16-bit applications for x86 architechture.
Why do most universities force you to learn the most outdated asm possible? Guess what, assholes, asm isn't like other code: once it's outdated, the skills you learn don't really translate well into modern programming. Nobody writes code for a fucking 286 anymore! It's not that hard to just throw a student into a modern computer's asm. They'll handle it, I promise!
Ahem. Anyways.
I don't know if the 1990 Borland assembler will let you do this, as when I took an ASM class we used an up-to-date version of gcc on a modern, 32-bit computer, like rational people, but you just call the printf function to print stuff to the screen, just like in C. In asm, you pass variables to a C function by pushing them to the stack in reverse order. Example: let's say eax (or, shit, you're in 16-bit, so just ax) has the memory address of a string. You use:
push ax
call prinf
pop ax
and you're good. Don't forget to do that pop, or you'll leave the stack unbalanced.
That might not work for him. It's been awhile since I've done ASM, but the 16-bit x86 compiler we used required us to go through the BIOS interrupt table, so he might have something approximating this:
I'm using Borland TASM circa 1990, doing 16-bit applications for x86 architechture.
Why do most universities force you to learn the most outdated asm possible? Guess what, assholes, asm isn't like other code: once it's outdated, the skills you learn don't really translate well into modern programming. Nobody writes code for a fucking 286 anymore! It's not that hard to just throw a student into a modern computer's asm. They'll handle it, I promise!
Ahem. Anyways.
I don't know if the 1990 Borland assembler will let you do this, as when I took an ASM class we used an up-to-date version of gcc on a modern, 32-bit computer, like rational people, but you just call the printf function to print stuff to the screen, just like in C. In asm, you pass variables to a C function by pushing them to the stack in reverse order. Example: let's say eax (or, shit, you're in 16-bit, so just ax) has the memory address of a string. You use:
push ax
call prinf
pop ax
and you're good. Don't forget to do that pop, or you'll leave the stack unbalanced.
That might not work for him. It's been awhile since I've done ASM, but the 16-bit x86 compiler we used required us to go through the BIOS interrupt table, so he might have something approximating this:
mov dx, offset SOME_VARIABLE
mov ax, 08
int 21h
And this would be why high-level languages were invented.
Look, the only reason a school would teach antiquated assembly language (not to be confused with teaching modern assembly language techniques, which when used properly can be extremely efficient) is sadism. Or possibly a professor's attempt to prove that the skills he learned in the eighties are still needed today.
Well, the book we are using is 32-bit intel, and uses all the 32-bit registers, but our teacher just likes using his TASm vice MASM. I actually havn't noticed anything different, outside of TASM using db vice byte, dw vice word, and the lack of specifically signed or unsigned number types.
Really, its nothing that I can't convert back and forth from TASM to MASM (which I also have installed, I just like my TASM via TextPad interface, heh).
myString db "Hello world!$"
mov dx, myString
mov ah, 09
int 21h
However, interrupt 21 function code 9 is designed to need that $ at the end of the string, to know when to stop incrementing the offset of the array and printing characters. I cannot use this interrupt with numbers. (I'm trying to get some output for my Fibonacci program.)
I've tried interrupt 212 function code 2, which recieves pulls a character from the dl register and prints it, however all I get is ascii garbage.
§"7YÉΘyb█=↑Um┬/±
I'm run my code through my debugger and the numbers I get are correct, so its just trying to output them.
(I apologize for the multiple posts, but my internet connection is being really shitty and times out if I post something too big... but only from my desktop... why does it hate me so...)
myString db "Hello world!$"
mov dx, myString
mov ah, 09
int 21h
However, interrupt 21 function code 9 is designed to need that $ at the end of the string, to know when to stop incrementing the offset of the array and printing characters. I cannot use this interrupt with numbers. (I'm trying to get some output for my Fibonacci program.)
I believe interrupt code 08 just pulls a single character, but I can't recall the specifics, you should have an int 21h table somewhere to tell you what's what.
Now, this is actually the trivial part of your program. In order to output numbers that you've actually done some work with, you're going to have to convert them from their internal format to ASCII.
I've tried interrupt 212 function code 2, which recieves pulls a character from the dl register and prints it, however all I get is ascii garbage.
§"7YÉΘyb█=↑Um┬/±
I'm run my code through my debugger and the numbers I get are correct, so its just trying to output them.
(I apologize for the multiple posts, but my internet connection is being really shitty and times out if I post something too big... but only from my desktop... why does it hate me so...)
You know that int 21h, ah = 02h deals with ASCII characters right? And that something like:
mov dl, 65
mov ah, 02
int 21h
will display ASCII character 65 (in this case, capital 'A') as opposed to the string "65"? You'll actually need to write a small function to convert from a number to a string so that it can be displayed.
Well, when you divide a number by the radix (10 for decimal) you get the first digit of the number as the remainder, ex: 256 / 10 = 25 R 6. Now you just need to figure out the offset from 0-9 decimal to '0'-'9' ASCII and add that to the remainder to get the character value for that digit. Once the quotient of the division is zero, you've run out of digits and you're done building that string.
And then I toss a $ into the next memory location directly after my newly built string, load the offset of the string into the dl, call int 21h and call it a day?
Well, when you divide a number by the radix (10 for decimal) you get the first digit of the number as the remainder, ex: 256 / 10 = 25 R 6. Now you just need to figure out the offset from 0-9 decimal to '0'-'9' ASCII and add that to the remainder to get the character value for that digit. Once the quotient of the division is zero, you've run out of digits and you're done building that string.
Uh, when you divide by the radix, it's the last digit that's the remainder. 6 is the last digit of 256.
So you'll have to build your string backwards is all. Say, allocate 6 bytes of memory for a 16-bit integer (maximum string : 65536$), plop the $ at the last byte, and build backwards from that one. Say, use es:si, and dec si as long as the remainders stay non-zero.
That way, when you're done, es:si points to the first character of the string. Alternatively, use whatever segment/offset pair the int 21h call requires.
Well, when you divide a number by the radix (10 for decimal) you get the first digit of the number as the remainder, ex: 256 / 10 = 25 R 6. Now you just need to figure out the offset from 0-9 decimal to '0'-'9' ASCII and add that to the remainder to get the character value for that digit. Once the quotient of the division is zero, you've run out of digits and you're done building that string.
Uh, when you divide by the radix, it's the last digit that's the remainder. 6 is the last digit of 256.
Sorry, I'm used to numbering digits from right to left. I hope that wasn't confusing, but the example was correct.
Posts
See how many books I've read so far in 2010
Why do most universities force you to learn the most outdated asm possible? Guess what, assholes, asm isn't like other code: once it's outdated, the skills you learn don't really translate well into modern programming. Nobody writes code for a fucking 286 anymore! It's not that hard to just throw a student into a modern computer's asm. They'll handle it, I promise!
Ahem. Anyways.
I don't know if the 1990 Borland assembler will let you do this, as when I took an ASM class we used an up-to-date version of gcc on a modern, 32-bit computer, like rational people, but you just call the printf function to print stuff to the screen, just like in C. In asm, you pass variables to a C function by pushing them to the stack in reverse order. Example: let's say eax (or, shit, you're in 16-bit, so just ax) has the memory address of a string. You use:
push ax
call prinf
pop ax
and you're good. Don't forget to do that pop, or you'll leave the stack unbalanced.
That might not work for him. It's been awhile since I've done ASM, but the 16-bit x86 compiler we used required us to go through the BIOS interrupt table, so he might have something approximating this:
mov dx, offset SOME_VARIABLE
mov ax, 08
int 21h
And this would be why high-level languages were invented.
Look, the only reason a school would teach antiquated assembly language (not to be confused with teaching modern assembly language techniques, which when used properly can be extremely efficient) is sadism. Or possibly a professor's attempt to prove that the skills he learned in the eighties are still needed today.
But now I'm ranting.
Really, its nothing that I can't convert back and forth from TASM to MASM (which I also have installed, I just like my TASM via TextPad interface, heh).
See how many books I've read so far in 2010
myString db "Hello world!$"
mov dx, myString
mov ah, 09
int 21h
However, interrupt 21 function code 9 is designed to need that $ at the end of the string, to know when to stop incrementing the offset of the array and printing characters. I cannot use this interrupt with numbers. (I'm trying to get some output for my Fibonacci program.)
See how many books I've read so far in 2010
§"7YÉΘyb█=↑Um┬/±
I'm run my code through my debugger and the numbers I get are correct, so its just trying to output them.
(I apologize for the multiple posts, but my internet connection is being really shitty and times out if I post something too big... but only from my desktop... why does it hate me so...)
See how many books I've read so far in 2010
I believe interrupt code 08 just pulls a single character, but I can't recall the specifics, you should have an int 21h table somewhere to tell you what's what.
Now, this is actually the trivial part of your program. In order to output numbers that you've actually done some work with, you're going to have to convert them from their internal format to ASCII.
Seems like 9 and 2 are the only screen I/Os. What about file handling?
See how many books I've read so far in 2010
You know that int 21h, ah = 02h deals with ASCII characters right? And that something like:
mov dl, 65
mov ah, 02
int 21h
will display ASCII character 65 (in this case, capital 'A') as opposed to the string "65"? You'll actually need to write a small function to convert from a number to a string so that it can be displayed.
File sharing can be done via int 21h, ah = 3dh.
See how many books I've read so far in 2010
See how many books I've read so far in 2010
See how many books I've read so far in 2010
Uh, when you divide by the radix, it's the last digit that's the remainder. 6 is the last digit of 256.
So you'll have to build your string backwards is all. Say, allocate 6 bytes of memory for a 16-bit integer (maximum string : 65536$), plop the $ at the last byte, and build backwards from that one. Say, use es:si, and dec si as long as the remainders stay non-zero.
That way, when you're done, es:si points to the first character of the string. Alternatively, use whatever segment/offset pair the int 21h call requires.