fork download
  1. section .data
  2.  
  3. msg: db "The number of command line arguments is "
  4. len equ $ - msg ;length of our dear string
  5. char db 'character'
  6. charlen db $ - char
  7. ;
  8. SECTION .bss
  9. cline:resb 81 ;space to hold command line arguments for output for argc
  10. result:resb 20 ;space to hold command line arguments for output for argv[0]
  11. ;
  12.  
  13. section .text
  14. global main ;must be declared for using gcc
  15. ;
  16. main: ;tell linker entry point
  17. ;
  18. mov ecx,0 ;count output characters
  19. pop eax ;reject this 32 bits
  20. pop eax : ;get argc
  21. add al, 30H ;convert integer to ascii
  22. mov edi, cline ;put char in output buffer cline
  23. mov byte[edi],al ;move argc into edi memory address
  24. inc ecx ;increment char count
  25. inc edi ;increment pointer to o/p buffer
  26. mov al, 0aH ;LF to end line
  27. mov byte[edi],al ;put it at end of output line
  28. inc ecx ;increment output char count
  29.  
  30. pop eax ;get argv[0]
  31. cmp eax,0
  32. jz message
  33. add eax,0
  34. add al, 30H ;convert integer to ascii
  35. mov edi, result ;put char in output buffer result
  36. mov byte[edi],al ;move argv[0] into edi memory address
  37. inc ecx ;increment output char count
  38. inc edi ;increment pointer to o/p buffer
  39.  
  40. message:
  41. mov edx,len ;length of string to write
  42. mov ecx,msg ;addr of string
  43. mov ebx, 1 ;file descriptor 1 = stdout
  44. mov eax, 4 ;"write" system call
  45. int 0x80 ;call the kernel
  46. ;
  47.  
  48. pop edx ;restore char count into edx for system call
  49. mov ecx,cline ;address of string
  50. mov ebx, 1 ;file descriptor 1=stdout
  51. mov eax, 4 ;"write" system call
  52. int 0x80 ;call the kernel
  53.  
  54. ;
  55. mov edx,charlen ;length of string to write
  56. mov ecx,char ;addr of string
  57. mov ebx, 1 ;file descriptor 1 = stdout
  58. mov eax, 4 ;"write" system call
  59. int 0x80 ;call the kernel
  60. ;
  61. pop edx ;restore char count into edx for system call
  62. mov ecx,result ;address of string
  63. mov ebx, 1 ;file descriptor 1=stdout
  64. mov eax, 4 ;"write" system call
  65. int 0x80 ;call the kernel
  66. ;
  67.  
  68. mov ebx, 0 ;exit with error code 0
  69. mov eax, 1 ;"exit" system call
  70. int 0x80 ;call the kernel
Success #stdin #stdout 0s 5288KB
stdin
import React, { useState } from "react";

export default function Calculator() {
  const [num1, setNum1] = useState("");
  const [num2, setNum2] = useState("");
  const [result, setResult] = useState(null);

  const calculate = (operator) => {
    const n1 = parseFloat(num1);
    const n2 = parseFloat(num2);
    if (isNaN(n1) || isNaN(n2)) {
      setResult("Invalid Input");
      return;
    }

    let res;
    switch (operator) {
      case "+":
        res = n1 + n2;
        break;
      case "-":
        res = n1 - n2;
        break;
      case "*":
        res = n1 * n2;
        break;
      case "/":
        res = n2 !== 0 ? n1 / n2 : "Cannot divide by zero";
        break;
      default:
        res = "Error";
    }
    setResult(res);
  };

  return (
    <div className="p-6 bg-gray-100 rounded-xl shadow-lg max-w-sm mx-auto">
      <h2 className="text-xl font-bold text-center mb-4">Simple Calculator</h2>
      <input
        type="number"
        placeholder="Num1"
        value={num1}
        onChange={(e) => setNum1(e.target.value)}
        className="w-full p-2 border rounded mb-2"
      />
      <input
        type="number"
        placeholder="Num2"
        value={num2}
        onChange={(e) => setNum2(e.target.value)}
        className="w-full p-2 border rounded mb-2"
      />
      <div className="flex justify-between">
        <button onClick={() => calculate("+")} className="px-4 py-2 bg-blue-500 text-white rounded">+</button>
        <button onClick={() => calculate("-")} className="px-4 py-2 bg-red-500 text-white rounded">-</button>
        <button onClick={() => calculate("*")} className="px-4 py-2 bg-green-500 text-white rounded">×</button>
        <button onClick={() => calculate("/")} className="px-4 py-2 bg-yellow-500 text-white rounded">÷</button>
      </div>
      <h3 className="mt-4 text-lg font-semibold text-center">Result: {result}</h3>
    </div>
  );
}
stdout
The number of command line arguments is