7
\$\begingroup\$

We already have a question about default I/O for general submissions. However, entries in machine code have different built-in I/O capabilities from entries in high-level languages. Should they be allowed by default to input/output differently?

In this question, consider a machine code function to be a program that includes a return or similar command. (Classifying machine code entries into programs vs. functions is a separate issue; if you disagree, respond in comments.)

The current consensus is that functions and full programs may do I/O using the same methods, but just in case that changes, I'm making a distinction. Some options for input and output (to be considered separately):

  • Through any port
  • Through a specified port
  • In any register
  • In a specified register (e.g. the accumulator)
  • Using cdecl/stdcall conventions (thanks, @feersum)

I was inspired to ask this question by my answer to the Truth Machine catalog, which uses the single data bus on a Motorola MC14500 microcontroller as I/O. The OP ruled that valid, but we should have defaults for the future.

\$\endgroup\$
  • \$\begingroup\$ Writing an answer as a function in x86 assembly is something I've been intending to try soon. In that case there are well-defined protocols for receiving and returning parameters (cdecl or stdcall). \$\endgroup\$ – feersum Nov 7 '15 at 7:10
  • \$\begingroup\$ What do you mean by port? \$\endgroup\$ – Peter Taylor Nov 7 '15 at 8:09
  • \$\begingroup\$ @PeterTaylor Port and port. \$\endgroup\$ – jimmy23013 Nov 7 '15 at 15:21
  • \$\begingroup\$ Maybe we should use stack (like functions is c do) when using systems that are capable for that? \$\endgroup\$ – Hannes Karppila Nov 8 '15 at 20:05
6
\$\begingroup\$

I don't think we should allow different IO methods for programs written in machine code or assembler. Instead I think we should allow some new input methods for all languages.

If we can use functions in languages like C, we sould be able to use them also in assembly. Therefore I think that we should allow programs to take parameters and return output through the stack.

Some platforms doesn't have a stack by default, so we should find alternative approach. Let's look at the x86 architecture. There used to be thing called BIOS. When DOS calls a BIOS function, it uses registers to pass arguments and get return values. I think that similarly we should allow programs to take arguments in registers and return values using them. Value in register can be either input/output value or pointer to it (e.g. pointer to C-style string).

That kind of functions should end with ret (or similar) statement.

\$\endgroup\$
  • \$\begingroup\$ Just write your code and put "Inline Assembly" (replace Assembly with FASM / TASM / NAMS etc.) in the answer header. It'll be valid for every challenge that allows functions. Standard would be to provide a ptr to a struct to the function and modify it in place. Standalone-assembly can just use invoke to access standard included files available in all major assemblers. (I.e. Assembly has absolutely no disadvantage against higher languages per se). :-) \$\endgroup\$ – mınxomaτ Nov 10 '15 at 0:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .