Guest User

Untitled

a guest
Jul 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. $ *subx*
  2. ```
  3. Welcome to SubX, a better way to program in machine code.
  4. SubX uses a subset of the x86 instruction set. SubX programs will run without modification on Linux computers.
  5. It provides a better experience and better error messages than programming directly in machine code, but you have to stick to the instructions it supports.
  6.  
  7. == Ways to invoke subx
  8. - Run tests:
  9. subx test
  10. - See this message:
  11. subx --help
  12. - Convert a textual SubX program into a standard ELF binary that you can run on your computer:
  13. subx translate <input 'source' file> <output ELF binary>
  14. - Run a SubX binary using SubX itself (for better error messages):
  15. subx run <ELF binary>
  16.  
  17. To start learning how to write SubX programs, run:
  18. subx help
  19. ```
  20.  
  21. $ *subx help*
  22. ```
  23. help on what?
  24. Available top-level topics:
  25. usage
  26. registers
  27. syntax
  28. opcodes
  29. ```
  30.  
  31. $ *subx help registers*
  32. ```
  33. SubX currently supports eight 32-bit integer registers: R0 to R7.
  34. R4 contains the top of the stack.
  35. There's also a register for the address of the currently executing instruction. It is modified by jumps.
  36. Various instructions modify one or more of three 1-bit 'flag' registers, as a side-effect:
  37. - the sign flag (SF): usually set if an arithmetic result is negative, or reset if not.
  38. - the zero flag (ZF): usually set if a result is zero, or reset if not.
  39. - the overflow flag (OF): usually set if an arithmetic result overflows.
  40. The flag bits are read by conditional jumps.
  41. We don't support non-integer (floating-point) registers yet.
  42. ```
  43.  
  44. $ *subx help syntax*
  45. ```
  46. SubX programs consist of segments, each segment in turn consisting of lines.
  47. Line-endings are significant; each line should contain a single instruction, macro or directive.
  48. Comments start with the '#' character. It should be at the start of a word (start of line, or following a space).
  49. Each segment starts with a header line: a '--' delimiter followed by the starting address for the segment.
  50. The starting address for a segment has some finicky requirements. But just start with a round number, and `subx` will try to guide you to a valid configuration.
  51. A good rule of thumb is to try to start the first segment at the default address of 0x08048000, and to start each subsequent segment at least 0x1000 (most common page size) bytes after the last.
  52. If a segment occupies than 0x1000 bytes you'll need to push subsequent segments further down.
  53. Currently only the first segment contains executable code (because it gets annoying to have to change addresses in later segments every time an earlier one changes length; one of those finicky requirements).
  54. Check out some examples in this directory (ex*.subx)
  55. Programming in machine code can be annoying, but let's see if we can make it nice enough to be able to write a compiler in it.
  56. ```
  57.  
  58. $ *subx help opcodes*
  59. ```
  60. Opcodes currently supported by SubX:
  61. 01: add r32 to rm32
  62. 03: add rm32 to r32
  63. 05: add imm32 to R0 (EAX)
  64. 09: rm32 = bitwise OR of r32 with rm32
  65. 0b: r32 = bitwise OR of r32 with rm32
  66. 0d: R0 = bitwise OR of imm32 with R0 (EAX)
  67. 21: rm32 = bitwise AND of r32 with rm32
  68. 23: r32 = bitwise AND of r32 with rm32
  69. 25: R0 = bitwise AND of imm32 with R0 (EAX)
  70. 29: subtract r32 from rm32
  71. 2b: subtract rm32 from r32
  72. 2d: subtract imm32 from R0 (EAX)
  73. 31: rm32 = bitwise XOR of r32 with rm32
  74. 33: r32 = bitwise XOR of r32 with rm32
  75. 35: R0 = bitwise XOR of imm32 with R0 (EAX)
  76. 39: set SF if rm32 < r32
  77. 3b: set SF if rm32 > r32
  78. 3d: subtract imm32 from R0 (EAX)
  79. 50: push R0 (EAX) to stack
  80. 51: push R1 (ECX) to stack
  81. 52: push R2 (EDX) to stack
  82. 53: push R3 (EBX) to stack
  83. 54: push R4 (ESP) to stack
  84. 55: push R5 (EBP) to stack
  85. 56: push R6 (ESI) to stack
  86. 57: push R7 (EDI) to stack
  87. 58: pop top of stack to R0 (EAX)
  88. 59: pop top of stack to R1 (ECX)
  89. 5a: pop top of stack to R2 (EDX)
  90. 5b: pop top of stack to R3 (EBX)
  91. 5c: pop top of stack to R4 (ESP)
  92. 5d: pop top of stack to R5 (EBP)
  93. 5e: pop top of stack to R6 (ESI)
  94. 5f: pop top of stack to R7 (EDI)
  95. 68: push imm32 to stack
  96. 74: jump disp8 bytes away if ZF is set
  97. 75: jump disp8 bytes away if ZF is not set
  98. 7c: jump disp8 bytes away if lesser (SF != OF)
  99. 7d: jump disp8 bytes away if greater or equal (SF == OF)
  100. 7e: jump disp8 bytes away if lesser or equal (ZF is set or SF != OF)
  101. 7f: jump disp8 bytes away if greater (ZF is unset, SF == OF)
  102. 81: combine rm32 with imm32 based on subop
  103. 87: swap the contents of r32 and rm32
  104. 89: copy r32 to rm32
  105. 8b: copy rm32 to r32
  106. 8f: pop top of stack to rm32
  107. b8: copy imm32 to R0 (EAX)
  108. b9: copy imm32 to R1 (ECX)
  109. ba: copy imm32 to R2 (EDX)
  110. bb: copy imm32 to R3 (EBX)
  111. bc: copy imm32 to R4 (ESP)
  112. bd: copy imm32 to R5 (EBP)
  113. be: copy imm32 to R6 (ESI)
  114. bf: copy imm32 to R7 (EDI)
  115. c3: return from most recent unfinished call
  116. c7: copy imm32 to rm32
  117. cd: software interrupt (0x80 only)
  118. e8: call disp32
  119. e9: jump disp16 bytes away
  120. eb: jump disp8 bytes away
  121. f4: halt
  122. f7: bitwise complement of rm32
  123. ff: jump/push/call rm32 based on subop
  124. Coming soon: `subx help operands` for details on words like 'r32' and 'disp8'.
  125. ```
Add Comment
Please, Sign In to add comment