Assembly Language Square Values
What would be the most efficient way to take an input 'x' and find the respective 'x^2' (of which is stored in another variable) with only the basic assembly operators? (Add, Sub, Store, etc.)
See also questions close to this topic
How to put array with many numbers to represent a matrix in DLX assembly language
I'm making an assembly language about Haar DWT and as you know, haar dwt needs a matrix represented from an image. I want an assembly language that able to put 64x64 or 128x128 or even 256x256 matrix. How do I do that?
I am new to this assembly thing, let alone to use DLX microprocessor. I have the assembly code for the calculation of the DWT itself. But somehow the biggest matrix I can put in is 4x4 matrix/16 values only. I don't know if it's the memory thing, or the fact that I calculate big floating point that is too heavy for the program, but I can't get it done. I have tried to change the space of haar_out, the M and N, but it didn't work too.
.data sqrt: .double 1.4142 haar_in: .double 148, 142, 130, 168, 166, 117, 138, 120, 116, 118, 109, 136, 99, 89, 123, 120 haar_out: .space 10000 M: .word 4 N: .word 4 K: .word 1 ; Register Usage ; GP: ; R0 => 0 ; R1 => M ; R2 => N ; R3.. => Internally used ; FP: ; F0 => 0 ; F8 => Square Root of 2 ; F2.. => Internally used
This is my .data, so whenever I'm calculating a number, I will load dp from haar_in to an FP register, then the result of the calculation will be stored in haar_out. Whenever I put more that 4x4 matrix, the message will be a timeout, an overflow, or illegal number. Help..
Can't `mov` directly to registers - x86 Assembly on OSX
I'm a total beginner in x86 Assembly (although I have some basic experience with MIPS and I'm pretty familiar with MIPS assembly code), and I'm trying to understand how it works. For the moment being I'm just working on a simple hello world program that just prints a string to
If I'm not mistaken, in order to print something to
stdoutthe following registers should contain the following values:
edxshould contain the length of the string
ecxshould contain the pointer to the string
ebxshould contain the file descriptor value (0x1 for
eaxshould contain the syscall value (0x4 for
However, while I've made sure that all the registers have the correct values (by checking with
lldb), I get nothing printed on
As I'm on an OSX machine, I'm assembling and linking with
ldrespectively, as follows:
$ nasm -f macho -O0 hello.asm $ ld -e _start -lSystem -macosx_version_min 10.8 hello.o -o hello
hello.asmis the source code file. The
-O0flag on the first command tells the assembler to not optimize the code, so that I can look at it later with
lldb; also the
_startlabel is the entry point to my program (see code below) and
-lSystemis needed or else
ldrefuses to compile (the
-macosx_version_minflag is there to silence
Here is the code that should work but doesn't:
section .data ; Beginning of our data section msg db "Hello, World!", 0xa ; String with a carriage-return len equ $ - msg ; String length in bytes section .text ; Start of the code indicator global _start ; Make the main function externally visible _syscall: ; Declaring a kernel call function int 0x80 ; Make the system call ret ; Return to the caller _start: ; Entry point for linker ; Write our string to standard output mov edx, len mov ecx, msg mov ebx, 1 mov eax, 4 ; System call number (sys_write) call _syscall ; Call the kernel mov ebx, 0 ; Exit code mov eax, 0x1 ; System call number (sys_exit) call _syscall ; Make the system call
This code fails in two points: it prints nothing, and also its exit code is not 0 (on my machine it returns 0x51).
However, if I push the values onto the stack, it works perfectly:
section .data ; Beginning of our data section msg db "Hello, World!", 0xa ; String with a carriage-return len equ $ - msg ; String length in bytes section .text ; Start of the code indicator global _start ; Make the main function externally visible _syscall: ; Declaring a kernel call function int 0x80 ; Make the system call ret ; Return to the caller _start: ; Entry point for linker ; Write our string to standard output push dword len ; Push message length onto stack (for EDX) push dword msg ; Push message to write onto stack (for ECX) push dword 1 ; Push file descriptor value (STDOUT) onto stack (for EBX) mov eax, 4 ; System call number (sys_write) call _syscall ; Call the kernel push dword 0 ; Exit code mov eax, 0x1 ; System call number (sys_exit) call _syscall ; Make the system call
What is causing this? Does it have something to do with register size? I want to work in 32-bit mode and I'm pretty sure I am, because I know that in order to assemble in 64-bit mode I need to call nasm with
Is there something else I'm missing?
Unable to boot from vm virtualbox
I tried to create an operating system using vmbox, surprisingly at first chance I got success in loading and display my operating system (actually it is Mike OS). Easily available in net. At first glance I run a bootloader and it displayed msg "error booting from floppy". Then I changed [bootdev] option set to CD ROM, then I run "bootloader.bin". And I got success in booting. After that I supplied operating system "kernel.bin" . And it worked properly. But when I tried to run again the same operating system again (I tried near about thousands of times) but I couldn't succeed. I deleted the ISO file which was running properly. Now I unable to understand what procedure I had followed at first time using that deleted file. Now I'm trying again but I didn't find any way. Please help.
Little Man Computer Integer Division with Remainder
I've managed to code an LMC program which works on this simulator for performing integer division. However if there is a remainder it goes into an infinite loop.
I'm trying to think of a way to just keep the quotient regardless of whether there is a remainder, but I'm stuck.
One idea was to increase the dividend by the original divisor and then check for a negative value for
DIVISORbefore branching. However, there is only "Branch if Zero" or "Branch if positive" available, so I would probably have to re-write the program from scratch to use the inverted logic.
Can anyone please provide a version which can handle non-exact division?
// CANT HANDLE NOT-EXACT DIVISION INP DIVIDEND STA DIVIDEND INP DIVISOR STA DIVISOR LOOP LDA DIVIDEND BRZ END SUB DIVISOR STA DIVIDEND LDA QUOTIENT ADD ONE STA QUOTIENT BRA LOOP END LDA QUOTIENT OUT SUB QUOTIENT STA QUOTIENT HLT DIVIDEND DAT DIVISOR DAT QUOTIENT DAT 0 ONE DAT 1
How to do a base conversion with Little Man Computer?
I need to convert a decimal number to a base between 2 and 9 using Little Man Computer. How do I proceed?
I believe successive divisions are the best method. In my opinion, I must write a code which divides two numbers, then save the integer ratio for the next division, as well as all of the remainders in an array of indefinite size, but I've been struggling with the division code for hours now. I tried searching for a code which divides two numbers, but all the ones I tried have mistakes/don't work. I'm stuck at the easiest part of the problem, I can't imagine how I'm ever going to be able to write a self-modifying code which manages an array of ever-increasing line positions and backtracks through it at the end to extract all the remainders. I'm at a loss here, any help would be appreciated.
how to convert a number from base 10 to any other base using Little Man Computer
I need to create a program that takes as the first input : A decimal number and as a second input the number of the base it will be converted to . then outputs the result of the conversion .
I looked everywhere on the internet but i cant seem to find anything that would help me move forward .
here is my code so far
INP number STA number INP base STA base LOOP LDA number BRZ END SUB base STA number LDA ANS ADD ONE STA ANS BRA LOOP END LDA ANS STO number SUB ANS STA ANS OUT BRA LOOP HLT number DAT base DAT ANS DAT 0 ONE DAT 1
I had been trying to convert 12 to binary I expect to get : 0 as remainder for the first division 0 for second 1 for 3rd 1 for 4th but I actually get only the first 2 remainders before it loops indefinitely because of the negatives numbers on the accumulator .