wats the program for the summation of 2n from n=0 to n=15 in assembly language for a z80?

1 Answer

Relevance
  • Anonymous
    10 years ago
    Favorite Answer

    I don't know Z80 Assembly, but I do know Intel x86 Asm (assemble with fasm):

    ===========================

    format PE console

    entry main

    include 'macro/import32.inc'

    section '.data' data readable writeable

    integer db "%i",0

    p db "pause>nul",0

    section '.code' code readable executable

    main:

    push ebp

    mov ebp,esp

    sub esp,8

    mov dword [ebp-4],0

    loopA:

    mov eax,dword [ebp-4]

    cmp eax,16

    jge breakA

    mov eax,dword [ebp-4]

    mov ecx,2

    mul ecx

    mov ecx,dword [ebp-8]

    add ecx,eax

    mov dword [ebp-8],ecx

    mov eax,dword [ebp-4]

    inc eax

    mov dword [ebp-4],eax

    jmp loopA

    breakA:

    sub esp,8

    mov dword [esp],integer

    mov eax,dword [ebp-8]

    mov dword [esp+4],eax

    call [printf]

    mov dword [esp],p

    call [system]

    mov dword [esp],0

    call [exit]

    section '.idata' import data readable

    library msvcrt,'msvcrt.dll'

    import msvcrt,\

    printf,'printf',\

    system,'system',\

    exit,'exit'

    ========================

    The above code is equivalent to this in C:

    #include "stdio.h"

    #include "stdlib.h"

    int main() {

    int i;

    int c;

    for (i=0;i<16;i++) {

    c=c+2*i;

    }

    printf("%i",c);

    system("pause>nul");

    return 0;

    }

Still have questions? Get your answers by asking now.