Guest User

Untitled

a guest
Jan 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. # *************************************************
  2. # * Subroutine: sbc *
  3. # * Description: Subtract memory with accumulator *
  4. # *************************************************
  5. .global exe_sbc
  6. exe_sbc:
  7. enter
  8.  
  9. andb $0b10111111, P # Clear overflow flag
  10.  
  11. # %al = accumulator
  12. movzbl A, %eax # Read accumulator into eax
  13.  
  14. # %bl = inverted memory
  15. movl ARG, %ebx # Read memory address into ebx
  16. movzbl (%ebx), %ebx # Read operand from memory into bl
  17.  
  18. ## BCD conversion
  19. movb P, %dh # Load P for checking
  20. andb $0b00001000, %dh # Filter out everything but the decimal flag
  21. cmpb $0b00001000, %dh # Check if decimal flag is set
  22. jne sbc_nofrombcd
  23.  
  24. pushl %ebx # Store ebx for later use
  25. pushl %eax # %eax as argument
  26. call frombcd # Convert from bcd to 2c
  27. addl $4, %esp # Clear %eax from stack
  28. popl %ebx # Retrieve %ebx
  29. pushl %eax # Save %eax for later use
  30.  
  31. pushl %ebx # %ebx as argument
  32. call frombcd # Convert from bcd to 2c
  33. addl $4, %esp # Clear %ebx from stack
  34. movl %eax, %ebx # Move return value to %ebx
  35. popl %eax # Retrieve %eax
  36.  
  37. sbc_nofrombcd:
  38.  
  39. # %cl = carry
  40. movzbl P, %ecx # Read proc status flag into %ecx
  41. andb $0b00000001, %cl # Filter out everything but the carry
  42.  
  43. pushl %eax # Push eax for overflow check
  44. pushl %ebx # Push ebx for overflow check
  45.  
  46. # %bl = negative memory
  47. xorb $0b11111111, %bl # Bit-invert memory value for addition
  48. addl %ecx, %ebx # Add carry to inverted memory
  49.  
  50. # %bl += %al
  51. addl %eax, %ebx # Add accumulator to negative memory
  52.  
  53. pushl %ebx # Push result for overflow check
  54. call setsbcoverflow # Check overflow
  55. popl %ebx # Retrieve ebx
  56. addl $4, %esp # Skip over original ebx
  57. popl %eax # Retrieve eax
  58.  
  59. pushl %ebx # Check carry
  60. call setcarry # ...
  61. popl %ebx # ...
  62.  
  63. movb %bl, A # Store result back into accumulator
  64.  
  65. movb P, %dh # Load P for checking
  66. andb $0b00001000, %dh # Filter out everything but the decimal flag
  67. cmpb $0b00001000, %dh # Check if decimal flag is set
  68. jne sbc_notobcd
  69.  
  70. movzbl A, %eax # Reload A value
  71. pushl %eax # %eax as argument
  72. call tobcd # Convert from bcd to 2c
  73. addl $4, %esp # Clear %eax from stack
  74. movb %al, A # Put result back in A
  75.  
  76. sbc_notobcd:
  77.  
  78. pushl %eax # Affect
  79. call setzero # zero and
  80. call setneg # negative
  81. addl $4, %esp # flags.
  82.  
  83. incw PC # Increment PC
  84.  
  85. return
Add Comment
Please, Sign In to add comment