Beispiel #1
0
def TestCTRReg():
    A = extarray.extarray('l', 1000)
    B = extarray.extarray('l', 1000)

    for i in xrange(1000):
        A[i] = i

    prgm = env.Program()
    code = prgm.get_stream()
    a = registers.esi
    b = registers.edi
    code.add(x86.mov(a, memory.MemRef(registers.ebp, 2 * _ws)))
    code.add(x86.mov(b, memory.MemRef(registers.ebp, 3 * _ws)))
    n = registers.ebx
    code.add(x86.mov(n, 1000))
    i_iter = syn_iter(code, n, mode=CTR)
    for i_ in i_iter:
        code.add(x86.mov(registers.eax, memory.MemRef(a, index=i_, scale=4)))
        code.add(x86.mov(memory.MemRef(b, index=i_, scale=4), registers.eax))

    params = env.ExecParams()
    params.p1 = A.buffer_info()[0] - _ws
    params.p2 = B.buffer_info()[0] - _ws

    prgm += code
    proc = env.Processor()
    proc.execute(prgm, mode='int', params=params)

    for i in range(len(B)):
        assert (B[i] == i)
Beispiel #2
0
def TestINCMemMem():
    A = extarray.extarray('i', 1000)
    B = extarray.extarray('i', 1000)

    for i in xrange(1000):
        A[i] = i

    prgm = env.Program()
    code = prgm.get_stream()
    a = registers.esi
    b = registers.edi
    code.add(x86.mov(a, memory.MemRef(registers.ebp, 2 * _ws)))
    code.add(x86.mov(b, memory.MemRef(registers.ebp, 3 * _ws)))
    n = memory.MemRef(registers.ebp, 4 * _ws)
    code.add(x86.mov(n, 1000))
    i_iter = syn_iter(code,
                      n,
                      mode=INC,
                      count_reg=memory.MemRef(registers.ebp, 5 * _ws),
                      clobber_reg=registers.eax)
    j = registers.ebx
    for i_ in i_iter:
        code.add(x86.mov(j, i_))
        code.add(x86.mov(registers.eax, memory.MemRef(a, index=j, scale=4)))
        code.add(x86.mov(memory.MemRef(b, index=j, scale=4), registers.eax))

    params = env.ExecParams()
    params.p1 = A.buffer_info()[0]
    params.p2 = B.buffer_info()[0]
    prgm += code
    proc = env.Processor()
    proc.execute(prgm, mode='int', params=params)

    for i in range(len(B)):
        assert (B[i] == i)
Beispiel #3
0
def TestDECMemMem_MemStep():
    A = extarray.extarray('l', 1000)
    B = extarray.extarray('l', 1000)

    for i in xrange(1000):
        A[i] = i

    prgm = env.Program()
    code = prgm.get_stream()
    a = registers.esi
    b = registers.edi
    code.add(x86.mov(a, memory.MemRef(registers.ebp, 2 * _ws)))
    code.add(x86.mov(b, memory.MemRef(registers.ebp, 3 * _ws)))
    n = memory.MemRef(registers.esp, 0)
    code.add(x86.sub(registers.esp, 12))
    code.add(x86.mov(n, 1000))
    #code.add(x86.push(1000))
    s = memory.MemRef(registers.esp, 2 * _ws)
    code.add(x86.mov(s, -4))
    i_iter = syn_iter(code,
                      n,
                      mode=DEC,
                      step=s,
                      count_reg=memory.MemRef(registers.esp, 1 * _ws),
                      clobber_reg=registers.eax)
    j = registers.ebx
    for i_ in i_iter:
        code.add(x86.mov(j, i_))
        code.add(x86.mov(registers.eax, memory.MemRef(a, index=j, scale=4)))
        code.add(x86.mov(memory.MemRef(b, index=j, scale=4), registers.eax))

    code.add(x86.add(registers.esp, 12))

    params = env.ExecParams()
    params.p1 = A.buffer_info()[0] - _ws
    params.p2 = B.buffer_info()[0] - _ws
    prgm += code
    proc = env.Processor()
    proc.execute(prgm, mode='int', params=params)

    for i in range(len(B) - 1, 0, -4):
        assert (B[i] == i)