Yazar: berkkuzu

  • Ardunio – UART practise

    /*
    
              Berk Muammer Kuzu - Converting decimal to binary and getting output via LEDs using UART
              
              kullanılan kart : Arduino MEGA 2560
    
    
    eklenebilir özellikler
    -işaret biti eklenebilir.
    -iki sayıdan daha fazla işlem yapabilen bir sistem tasarlanabilir.
    -6 led bize maks 63 e kadar işlem yapma olanağı tanıyor bu sorun girilmeye çalışılabilir. 63 den sonrasında sadece son 6 bite bakarak çıktı veriyor.
    */
    
    
    const int ledPins[6] = {13, 12, 11, 10, 9, 8}; // order LSB to MSB 
    
    void setup() {
      Serial.begin(9600);
      for (int i = 0; i < 6; i++) {
        pinMode(ledPins[i], OUTPUT);
      }
      Serial.println("Please enter your operation(ex: 3+6): ");
    }
    
    void loop() {
      if (Serial.available()) {
        int x = Serial.parseInt();
        char op = Serial.read();        
        int y = Serial.parseInt();     
        int result = 0;
    
      
        switch (op) {
          case '+':
            result = x + y;
            break;
          case '-':
            result = x - y;
            break;
          case '*':
            result = x * y;
            break;
          case '/':
            if (y != 0) result = x / y;
            else {
              Serial.println("ERROR: Division by 0!");
              clearLeds();
              resetSerial();
              return;
            }
            break;
          default:
            Serial.println("INVALID OPERATION");
            clearLeds();
            resetSerial();
            return;
        }
    
        Serial.print("Result: ");
        Serial.println(result);
    
        for (int i = 0; i < 6; i++) {
          digitalWrite(ledPins[i], bitRead(result, i));
        }
    
        resetSerial();
      }
    }
    
    void clearLeds() {
      for (int i = 0; i < 6; i++) {
        digitalWrite(ledPins[i], LOW);
      }
    }
    
    void resetSerial() {
      while (Serial.available()) Serial.read();
    }
    
  • MIPS ASSEMBLY – CALCULATOR

    ##################################################################################
    #ASSEMBLY CALCULATOR
    #BERK MUAMMER KUZU
    ##################################################################################
    
    ##################################################################################
    .data
    string1: .asciiz "Enter the first number: \n"
    opChose: .asciiz "Enter the operand: \n"
    string2: .asciiz "Enter the second number: \n"
    resultMsg: .asciiz "Result: "
    errorMsg: .asciiz "Entered wrong operand. Options +, -, *, / \n"
    newLine: .asciiz "\n"
    carryBit: .asciiz "Remainder: "
    
    op1: .word 1
    op2: .word 1
    op: .word 2
    
    out: .word 1 #output
    remainder: .word 1
    ##################################################################################
    
    ##################################################################################
    .text
    main:
    li $v0, 4
    la $a0, string1
    syscall #print string 1
    
    li $v0, 5
    syscall #input op1
    sw $v0, op1 #save op1 to the memory
    
    opType: #operation function
    li $v0, 4
    la $a0, opChose
    syscall #print opChose
    
    la $a0, op
    la $a1, 2
    li $v0, 8
    syscall #select the operation input
    lw $t0, 0($a0)
    
    #####NEW LINE######
    li $v0, 4
    la $a0, newLine
    syscall
    ###################
    
    ##Operand Check##
    li $t1, '+'
    li $t2, '-'
    li $t3, '*'
    li $t4, '/'
    ##################
    
    beq $t0, $t1, secondOp
    beq $t0, $t2, secondOp
    beq $t0, $t3, secondOp
    beq $t0, $t4, secondOp
    j Error
    
    ##
    secondOp:
    li $v0, 4
    la $a0, string2
    syscall #print string 2
    li $v0, 5
    syscall
    sw $v0, op2
    
    lw $s1, op1
    lw $s2, op2
    lw $s0, out
    lw $s4, remainder
    ##
    
    ###################### + - * / ######################
    beq $t0, $t1, addb
    beq $t0, $t2, sub_
    beq $t0, $t3, mult_
    beq $t0, $t4, div_
    
    addb:
    add $s0, $s1, $s2
    sw $s0, out
    j print
    
    sub_:
    sub $s0, $s1, $s2
    sw $s0, out
    j print
    
    mult_:
    mult $s1, $s2
    mflo $s0
    sw $s0, out
    j print
    
    div_:
    div $s1, $s2
    mflo $s0 
    mfhi $s4 
    sw $s4, remainder
    li $v0, 4
    la $a0, carryBit
    syscall #print carryBit
    li $v0, 1
    lw $a0, remainder
    syscall
    #####NEW LINE######
    li $v0, 4
    la $a0, newLine
    syscall
    ###################
    sw $s0, out
    j print
    ###################### + - * / ######################
    
    ##
    print:
    li $v0, 4
    la $a0, resultMsg
    syscall #print resultMsg
    
    li $v0, 1
    lw $a0, out
    syscall #print out
    
    #####NEW LINE######
    li $v0, 4
    la $a0, newLine
    syscall
    ###################
    
    #####NEW LINE######
    li $v0, 4
    la $a0, newLine
    syscall
    ###################
    
    j main
    ##
    
    ##
    Error:
    li $v0, 4
    la $a0, errorMsg
    syscall #print errorMsg
    j opType
    ##
    ##################################################################################