Guest User

Assembly

a guest
Jan 7th, 2024
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | Source Code | 0 0
  1. transmitter:
  2. # Transmitter code
  3. li $v0, 4
  4. la $a0, enter_char
  5. syscall
  6.  
  7. # Read a character from the user
  8. li $v0, 12
  9. syscall
  10. move $t3, $v0 # Store the input character in $t3
  11.  
  12. # Display ASCII code in hex and decimal
  13. li $v0, 4
  14. la $a0, ascii_code_msg
  15. syscall
  16. li $v0, 34 # Print hexadecimal integer
  17. move $a0, $t3
  18. syscall
  19. li $v0, 4
  20. la $a0, ascii_dec_msg
  21. syscall
  22. li $v0, 1 # Print integer
  23. move $a0, $t3
  24. syscall
  25.  
  26. # Convert the character to 8-bit binary with parity bit
  27. li $t4, 0 # Initialize counter for setting bits
  28. li $t5, 8 # Number of data bits (ASCII uses 8 bits)
  29. li $t6, 0 # Initialize parity bit to 0
  30.  
  31. convert_loop:
  32. srl $t7, $t7, 1 # Shift right to get the next bit
  33. andi $t8, $t3, 1 # Extract the LSB of the input character
  34. xor $t6, $t6, $t8 # Update parity bit
  35. sll $t6, $t6, 1 # Shift left to make room for the next bit
  36. bnez $t7, calculate_parity_transmitter # Repeat until all bits are processed
  37.  
  38. # Add the parity bit to the binary representation
  39. or $t6, $t6, $t7
  40.  
  41. # Display binary equivalent with parity bit
  42. li $v0, 4
  43. la $a0, binary_output
  44. syscall
  45.  
  46. # Print the binary representation
  47. li $t4, 9 # Number of bits including parity bit
  48. print_binary_transmit:
  49. srl $t4, $t4, 1 # Shift right to get the next bit
  50. andi $t7, $t6, 1 # Extract the LSB of the binary representation
  51. li $v0, 1
  52. move $a0, $t7
  53. syscall
  54. sll $t6, $t6, 1 # Shift left to get the next bit
  55. bnez $t4, print_binary_transmit # Repeat until all bits are printed
  56.  
  57. # Display parity bit
  58. li $v0, 4
  59. la $a0, calculate_parity
  60. syscall
  61.  
  62. # Print the parity result
  63. li $v0, 4
  64. la $a0, parity_result
  65. syscall
  66.  
  67. # Display parity bit result
  68. li $v0, 1
  69. move $a0, $t7
  70. syscall
  71.  
  72. # Display encapsulated message
  73. li $v0, 4
  74. la $a0, encapsulated_msg
  75. syscall
  76.  
  77. # Print encapsulated message
  78. li $t4, 9 # Number of bits including parity bit
  79. print_encapsulated_msg:
  80. srl $t4, $t4, 1 # Shift right to get the next bit
  81. andi $t7, $t6, 1 # Extract the LSB of the binary representation
  82. li $v0, 1
  83. move $a0, $t7
  84. syscall
  85. srl $t6, $t6, 1 # Shift right to get the next bit
  86. bnez $t4, print_encapsulated_msg # Repeat until all bits are printed
  87.  
  88. # Display sending message
  89. li $v0, 4
  90. la $a0, send_msg
  91. syscall
  92.  
  93. j main # Return to the main menu
Advertisement
Add Comment
Please, Sign In to add comment