hello sorry which method is the correct one we solved a question me and my friend in different methods and we went to our prof he said his method is the correct one and i couldn't get his idea so this one the first one is my way of solution
oh first of all the question :P is to write a FUNCTION ((xvy)^z)*2 and where x y and z are memory locations a000h,a001h,a0002h and store the result in a003 and a004 ( 8085)
MY SOLUTION
LXI H, A000H
MOV A,M
INX H
ORA M
INX H
ANA M
MVI B,02H
MOV A,B
LOOP : ADD B
DCR B
JNZ LOOP
STA A003
STA A004
HLT

. THAT WAS MY WAY AND PLZ IF THERE IS A MISTAKE JUST SHOW ME WHERE IS IT AND MY FRIEND SOLUTION WHICH IS THE CORRECT ONE :(

MVI D,00H
LXI H,A00H
MOV A,M
INX H
ORA M
INX H
ANA M
ADD A
JNC LP
INR D
LP : INX H

MOV M,A
INX H
MOV M,D
HLT


THNX IN ADVANCE GUYS

Okay, I'm flipping this back at you. Note the comments and decide for yourself!

By the way. Did you mean
((xvy)^z)*2
((x OR y ) AND z ) * 2

then next time...
((x | y) & z) * 2

Or did you mean

((x OR Y ) XOR z ) * 2

Or

((X OR Y ) to the power of Z ) * 2

You need to watch your operators...

But anyway, note the following...

LXI H, A000H	; HL=A000h  

    ;   (x | y)
  MOV A,M		; A=(HL)
  INX H			; HL++
  ORA M			; A = A | (HL)
  INX H			; HL++

   ; (x | y) & z
  ANA M			; A = A & (HL)

  MVI B,02H		; B = 2
  MOV A,B		; A = B
;;;; *****   Just destroyed A ****

LOOP :
  ADD B			; A = A + B
  DCR B			; B--
  JNZ LOOP      ; Loop until B = 0

  STA A003
  STA A004
  HLT 


??? WHY ALL THE WORK

Once you have   A = (x|y)&z
then
ADD A    ;  A = A + A     thus    A = A*2  thus  ((x|y)&z)*2

And that other snippet

MVI D,00H		; D = 0
  LXI H,A00H    ; HL=A00   <==    A00h or A000h  ????

  MOV A,M		; A=(HL)
  INX H			; HL++

  ORA M			; A = A | (HL)
  INX H			; HL++

  ANA M			; A = A & (HL)
  ADD A			; A = A + A
  JNC LP        ; Hop

  INR D

LP :
  INX H			; HL++
  MOV M,A		; (HL) = A
  INX H			; HL++
  MOV M,D		; (HL) = D
  HLT

Edited 7 Years Ago by wildgoose: n/a

This article has been dead for over six months. Start a new discussion instead.