Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- transmitter:
- # Transmitter code
- li $v0, 4
- la $a0, enter_char
- syscall
- # Read a character from the user
- li $v0, 12
- syscall
- move $t3, $v0 # Store the input character in $t3
- # Display ASCII code in hex and decimal
- li $v0, 4
- la $a0, ascii_code_msg
- syscall
- li $v0, 34 # Print hexadecimal integer
- move $a0, $t3
- syscall
- li $v0, 4
- la $a0, ascii_dec_msg
- syscall
- li $v0, 1 # Print integer
- move $a0, $t3
- syscall
- # Convert the character to 8-bit binary with parity bit
- li $t4, 0 # Initialize counter for setting bits
- li $t5, 8 # Number of data bits (ASCII uses 8 bits)
- li $t6, 0 # Initialize parity bit to 0
- convert_loop:
- srl $t7, $t7, 1 # Shift right to get the next bit
- andi $t8, $t3, 1 # Extract the LSB of the input character
- xor $t6, $t6, $t8 # Update parity bit
- sll $t6, $t6, 1 # Shift left to make room for the next bit
- bnez $t7, calculate_parity_transmitter # Repeat until all bits are processed
- # Add the parity bit to the binary representation
- or $t6, $t6, $t7
- # Display binary equivalent with parity bit
- li $v0, 4
- la $a0, binary_output
- syscall
- # Print the binary representation
- li $t4, 9 # Number of bits including parity bit
- print_binary_transmit:
- srl $t4, $t4, 1 # Shift right to get the next bit
- andi $t7, $t6, 1 # Extract the LSB of the binary representation
- li $v0, 1
- move $a0, $t7
- syscall
- sll $t6, $t6, 1 # Shift left to get the next bit
- bnez $t4, print_binary_transmit # Repeat until all bits are printed
- # Display parity bit
- li $v0, 4
- la $a0, calculate_parity
- syscall
- # Print the parity result
- li $v0, 4
- la $a0, parity_result
- syscall
- # Display parity bit result
- li $v0, 1
- move $a0, $t7
- syscall
- # Display encapsulated message
- li $v0, 4
- la $a0, encapsulated_msg
- syscall
- # Print encapsulated message
- li $t4, 9 # Number of bits including parity bit
- print_encapsulated_msg:
- srl $t4, $t4, 1 # Shift right to get the next bit
- andi $t7, $t6, 1 # Extract the LSB of the binary representation
- li $v0, 1
- move $a0, $t7
- syscall
- srl $t6, $t6, 1 # Shift right to get the next bit
- bnez $t4, print_encapsulated_msg # Repeat until all bits are printed
- # Display sending message
- li $v0, 4
- la $a0, send_msg
- syscall
- j main # Return to the main menu
Advertisement
Add Comment
Please, Sign In to add comment