LC3シミュレータ用のプログラムを作成しようとしています。メモリ内の別の場所に格納されている2進数の1の数をカウントできます。ここで私はこれまで持っているものです。LC3シミュレータを使用して2進数の1の数をカウントする
0011 0001 0000 0000 ; Start the data at memory location x3100
0110 1010 1111 0001 ; Hex number stored at x3000
0011 0000 0000 0000 ; Start the program at x3000
0101 001 001 1 00000 ; Clear R1 (Contain address of number)
0101 010 010 1 00000 ; Clear R2 (Counter for amount of 1's)
0001 011 011 1 00001 ; Load R3 with 1 (Number for 'and-ing' with number getting checked)
;^cant do this line since that is a decimal 1 not binary one therefore it wouldnt left shift
; and cant store and get a binary number in memory
0001 100 100 1 01111 ; Load R4 with 16 (Loop loops til 0)
1110 001 011111100 ; Load R1 with address of number
0110 101 001 000000 ; Load R5 with the number stored at x3100
0101 110 101 000 011 ; And R3 with R5 store result in R6
; If number is not zero, increment R2 by 1
0001 011 011 000 011 ; Add R3 with itself to make a left shift
0001 100 100 1 11111 ; Decrement R4 by 1
; Loop to x3006 (When R3 is 'And-ed' with R5) if R4 isnt 0
0011 010 011111101 ; Store value from R2 in x3101
1111 0000 00100101 ; Halt (Is this correct?) set breakpoint here
私は特定の値だけでなく、どのように背の条件が満たされない場合、特定のポイントにループするをチェックするための「if文」を作る方法として混乱しています。実際に1の数をカウントする方法についての私の考え方は、結果の値が0でない場合は "0000000000000001"でチェックされていた元の2進数をANDし、 "1のカウンター"に1を加えてから1の値を元の番号の次の値を確認してください。私はバイナリではなくレジスタ3に小数点1を格納していて、左にシフトできないと思っていたので、特定の行を実行できませんでした。私の制限の1つは、x3100とx3101よりもメモリ内の他の場所を使用して元の数を保存し、それぞれ1の量を保存することができないということです。
ビットマスクは非常に便利だと聞いたことがありますが、私は高低を検索して使い方を見つけることができません。どんな助けもありがとう、ありがとう!