Ideal statistical sample formula

August 13th, 2009 Leave a comment Go to comments

Calculate the ideal statistical sample from given input values using x86 Linux assembler (NASM)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
extern printf, scanf

section .data
    b: dq 1.645
    msg_p: db 'Hoeveel is p: ', 0
    msg_q: db 'Hoeveel is q: ', 0
    msg_n: db 'Hoeveel is de nauwkeurigheid: ', 0
    msg_o: db 'De ideale steekproefgrootte is: %d', 10, 0
    scanint: db '%d', 0

section .bss
    p: resd 1
    q: resd 1
    n: resd 1
    f: resd 1

section .text
    global _start
_start:
    ; p inlezen
    push msg_p
    call printf
    add esp, 4
    push p
    push scanint
    call scanf
    add esp, 8

    ; q inlezen
    push msg_q
    call printf
    add esp, 4
    push q
    push scanint
    call scanf
    add esp, 8

    ; nauwkeurigheid inlezen
    push msg_n
    call printf
    add esp, 4
    push n
    push scanint
    call scanf
    add esp, 8

    ; formule uitrekenen
    mov eax, [n]
    mul dword [n]
    mov [n], eax
    fld qword [b]
    fmul qword [b]
    fimul dword [p]
    fimul dword [q]
    fidiv dword [n]
    fistp dword [f]

    ; resultaat weergeven
    push dword [f + 4]
    push dword [f]
    push msg_o
    call printf
    add esp, 12

    ; return 0
    mov eax, 1
    mov ebx, 0
    int 80h
VN:F [1.6.3_896]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • Twitter
  1. No comments yet.
  1. No trackbacks yet.