section .data msg: db "The number of command line arguments is " len equ $ - msg ;length of our dear string char db 'character' charlen db $ - char ; SECTION .bss cline:resb 81 ;space to hold command line arguments for output for argc result:resb 20 ;space to hold command line arguments for output for argv[0] ; section .text global main ;must be declared for using gcc ; main: ;tell linker entry point ; mov ecx,0 ;count output characters pop eax ;reject this 32 bits pop eax : ;get argc add al, 30H ;convert integer to ascii mov edi, cline ;put char in output buffer cline mov byte[edi],al ;move argc into edi memory address inc ecx ;increment char count inc edi ;increment pointer to o/p buffer mov al, 0aH ;LF to end line mov byte[edi],al ;put it at end of output line inc ecx ;increment output char count pop eax ;get argv[0] cmp eax,0 jz message add eax,0 add al, 30H ;convert integer to ascii mov edi, result ;put char in output buffer result mov byte[edi],al ;move argv[0] into edi memory address inc ecx ;increment output char count inc edi ;increment pointer to o/p buffer message: mov edx,len ;length of string to write mov ecx,msg ;addr of string mov ebx, 1 ;file descriptor 1 = stdout mov eax, 4 ;"write" system call int 0x80 ;call the kernel ; pop edx ;restore char count into edx for system call mov ecx,cline ;address of string mov ebx, 1 ;file descriptor 1=stdout mov eax, 4 ;"write" system call int 0x80 ;call the kernel ; mov edx,charlen ;length of string to write mov ecx,char ;addr of string mov ebx, 1 ;file descriptor 1 = stdout mov eax, 4 ;"write" system call int 0x80 ;call the kernel ; pop edx ;restore char count into edx for system call mov ecx,result ;address of string mov ebx, 1 ;file descriptor 1=stdout mov eax, 4 ;"write" system call int 0x80 ;call the kernel ; mov ebx, 0 ;exit with error code 0 mov eax, 1 ;"exit" system call int 0x80 ;call the kernel
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>
);
}