logo
down
shadow

Finding GCD of an array of n numbers in assembly without external variables


Finding GCD of an array of n numbers in assembly without external variables

By : JustNoob
Date : October 16 2020, 06:10 PM
Hope this helps Step 1, cleanup and corrections
Removing redundant instructions, re-arrangeing the code for less jumping, removing the potential infinite loop if 2 identical numbers are used and zeroing EDX before each division:
code :
    mov  eax, intArray[0]
    mov  ebx, intArray[1]

major:
    cmp  eax, ebx
    jg   nextstep
    xchg eax, ebx
nextstep:
    cmp  ebx, 0
    je   zerob
modulus:
    xor  edx, edx
    div  ebx
    mov  eax, ebx
    mov  ebx, edx
    jmp  nextstep

zerob:
    mov  MCD, eax
fine:
    mov  ecx, num       ;Number of elements
    lea  esi, intArray[0]
    lodsd               ;First number in array
    dec  ecx
    jz   DONE

AGAIN:
    mov  ebx, [esi]     ;Next number in array
    add  esi, 4

major:
    cmp  eax, ebx
    jg   nextstep
    xchg eax, ebx
    jmp  nextstep
modulus:                ;Inner loop
    xor  edx, edx
    div  ebx
    mov  eax, ebx
    mov  ebx, edx
nextstep:
    test ebx, ebx
    jnz  modulus

    dec  ecx
    jnz  AGAIN

DONE:
    mov  MCD, eax
fine:


Share : facebook icon twitter icon
Finding Consecutive numbers From a Arithmetic series in an Array of random numbers

Finding Consecutive numbers From a Arithmetic series in an Array of random numbers


By : user34943
Date : March 29 2020, 07:55 AM
Does that help An O(i) solution using additional storage space would be to use a bit vector of size i initialised to 0. Iterate through the array and set the entry j to one if you encounter n*j. After that, find the number of ones at the beginning of the bit vector.
Loading external web.config variables when invoking a method in an external assembly

Loading external web.config variables when invoking a method in an external assembly


By : user2967438
Date : March 29 2020, 07:55 AM
I wish this helpful for you You may need to register with the AppDomain.CurrentDomain.TypeResolve event. This link has an example of how to use it. http://msdn.microsoft.com/en-us/library/system.appdomain.typeresolve.aspx
Finding the distance between the two closest numbers in an array of n numbers. (Presorted Arrays)

Finding the distance between the two closest numbers in an array of n numbers. (Presorted Arrays)


By : Ryan McGraw
Date : March 29 2020, 07:55 AM
this will help Loops are not identical. In the for loop i is increased in each iteration, while in the while loop i is increased only in some cases. An identical while loop would be:
code :
while(i<n)
{
    if(a[i]==current)
        i++;
    else
    {
        currentmin=a[i]-a[i-1];
        if(currentmin<arraymin)
        {
            arraymin=currentmin;
            current=a[i];
        }
        i++;
    }
}
Finding odd numbers in assembly

Finding odd numbers in assembly


By : Stefan Kern
Date : March 29 2020, 07:55 AM
it fixes the issue I'm not sure if you just forgot the extra subs, or if you thought ARM had branch delay slots, but you're only decrementing a2 in the "even" case.
Note that beq odd is unnecessary since you could use conditional execution instead, which will be more efficient:
code :
    tst a4, #1
    addne a3, a3, #1      @ if (a4 & 1) a3++ 
    subs a2, a2, #1
    bne elop
    mov a1, a3
    ldmfd sp!,{v1-v6,pc}
How to pass variables to a external assembly function

How to pass variables to a external assembly function


By : user3304941
Date : March 29 2020, 07:55 AM
hop of those help? If you compile your C into 32-bit code with the default GCC options (not -mregparm=3 like the Linux kernel uses), then on function entry the first argument is on the stack just above the return address (at [esp+4]), but that offset changes after you push anything or move ESP around.
You can use [ebp+8] after setting up a traditional stack pointer (which doesn't change during the function even when ESP does).
code :
;bits 32              ; unneeded, nasm -felf32 implies this.
global asm_function   ; include asm_function in ELF .o symbol table for linking
section .text
asm_function:
    push ebp
    mov ebp, esp
    mov eax, [ebp+8]  ; return the first argument
    mov esp, ebp
    pop ebp
    ret
global _asm_function
global asm_function  ; make both names of the function global
section .text
_asm_function:
asm_function:        ; make both symbols point to the same place
    push ebp
    mov ebp, esp
    mov eax, [ebp+8]
    mov esp, ebp
    pop ebp
    ret
Related Posts Related Posts :
  • reading a BYTE as a DWORD in Masm
  • Print double-word number to string
  • 8086 assembly right mouse click interrupts
  • how to replace a text in a file in assembly using DOS instruction
  • How to pass argv arguments to execv in asm on 64-bit (linux)
  • What's the difference between the "/FAs command line option" (generate asm output) or the "Goto Disassemb
  • I am not understanding this assemby language program for what(what will be the input or output)
  • Loading the red component of a 24-bit bitmap image into an array
  • How do old CPUs execute the new ENDBR64 and ENDBR32 instructions?
  • Is it possible to get LLVM-IR from Assembly file?
  • Which value does EDX have after logic NEG and AND instructions?
  • intterrupt that checks if a key was pressed and reads which key it was
  • Objdump swapping fsubrp to fsubp on compiled assembly?
  • Working with percentages using integer division in x86 assembly
  • IDIVQ instruction works odd . . . 16 mod 100 = 0?
  • ASSUME directive using masm
  • shift right and shift left assembly language
  • Is it possible to wake up intel cores with INIT-SIPI-SIPI sequence with all cores in real mode?
  • Bit Difference between 2 binary numbers in MIPS Assembly
  • How to find minimum signed value in array in assembly
  • MIPS: load byte instruction
  • How to deny or invert the memory address
  • Reverse byte order in XMM or YMM register?
  • How to print ASCII array in Assembly?
  • What does it mean by a branch penalty?
  • Copying to arrays in NASM
  • Is there any valid use for a sign-preserving left shift?
  • How does CPU perform operation that manipulate data that's less than a word size
  • Check if user input leads to overflow
  • Get C string length of a 16 or 32-byte fixed-size buffer? (XMM or YMM register width)
  • MIPS little or big endian when encoding as hex
  • How to calculate the sum of a sequence of powers of 2 in x86?
  • How to make timer works? Call int 4ah 5 seconds after start
  • Dword conversion to dec in little endian
  • Is there a way to subtract packed unsigned doublewords, saturated, on x86, using MMX/SSE?
  • What does a program (the assembly) that uses a GPU even look like?
  • Register content after execution
  • Explain how the flags work in conditional jumps in Assembly language
  • segmentation fault while trying to run graphics in yasm
  • How to alloc a segment of memory using BIOS service?
  • Sum of two numbers (each 2 characters) in assembly 8086
  • How does LLVM handle the x86 flag register?
  • How to read hardware input using emu8086
  • Assigning value to the variable present in previous line using $ sign
  • Different Segments may collapse with each other
  • How do we track values of different registers while coding a large program
  • Floating-point addition assembly algorithm
  • How would i make this a decryption instead of an encryption?
  • Do two consecutive labels form two different basic block or are they the same in assembly
  • How to make audio driver for MS-DOS?
  • Where is the time stamp located in a file? Want to change it using assembly
  • 8086 assembly register indirect MOV instruction
  • Which 2 cases aren't solved with this code?
  • Finding first and last capital letter in user input
  • I want to convert x86 Linux shellcode with system calls to ARM Linux system calls
  • Why do I get another result?
  • String printer doesn't print newlines
  • .set label, . Vs. label: GNU AS
  • Implementing while loop in 68k
  • Comparing List/Make-list & Vector/Make-array in Common Lisp
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk